Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "pry-byebug"
- class OrangeTree
- attr_accessor :age, :fruits, :height, :tree_end
- def initialize
- @age = 0
- @height = 0
- @fruits = 0
- @tree_end = rand(51..100)
- end
- def one_year_passes!
- @age += 1 unless @age.equal?(@tree_end)
- height_tree if @age <= 10
- fruit_production if (6..15).include?(@age)
- end
- def fruit_production
- @fruits = 100 if (6..9).include?(@age)
- @fruits = 200 if (10..14).include?(@age)
- @fruits = 0 if @age >= 15
- end
- def height_tree
- return @height += 1
- end
- def dead?
- return @age == @tree_end
- end
- def pick_a_fruit!
- return @fruits -= 1 if @fruits.positive?
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment