class LemonadeStand::Weather
Public Class Methods
new(type)
click to toggle source
# File lib/lemonade_stand/weather.rb, line 5 def initialize type @type = type end
weather_for(day)
click to toggle source
# File lib/lemonade_stand/weather.rb, line 17 def self.weather_for day type = if day.number < 3 :sunny else case rand(10) when 0..5 then :sunny when 6..7 then :cloudy else :hot_and_dry end end new type end
Public Instance Methods
method_missing(meth, *args, &blk)
click to toggle source
# File lib/lemonade_stand/weather.rb, line 9 def method_missing(meth, *args, &blk) meth.to_s == "#{@type}?" end
to_s()
click to toggle source
# File lib/lemonade_stand/weather.rb, line 13 def to_s @type.to_s.split('_').map { |x| x == 'and' ? x : x.capitalize! }.join(' ') end