rafamsilva

Untitled

Jan 7th, 2023 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.68 KB | None | 0 0
  1. require "pry-byebug"
  2.  
  3. class OrangeTree
  4.   attr_accessor :age, :fruits, :height, :tree_end
  5.  
  6.   def initialize
  7.     @age = 0
  8.     @height = 0
  9.     @fruits = 0
  10.     @tree_end = rand(51..100)
  11.   end
  12.  
  13.   def one_year_passes!
  14.     @age += 1 unless @age.equal?(@tree_end)
  15.     height_tree if @age <= 10
  16.     fruit_production if (6..15).include?(@age)
  17.   end
  18.  
  19.   def fruit_production
  20.     @fruits = 100 if (6..9).include?(@age)
  21.     @fruits = 200 if (10..14).include?(@age)
  22.     @fruits = 0 if @age >= 15
  23.   end
  24.  
  25.   def height_tree
  26.     return @height += 1
  27.   end
  28.  
  29.   def dead?
  30.     return @age == @tree_end
  31.   end
  32.  
  33.   def pick_a_fruit!
  34.     return @fruits -= 1 if @fruits.positive?
  35.   end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment