Class: LemonadeStand::Weather
- Inherits:
-
Object
- Object
- LemonadeStand::Weather
show all
- Defined in:
- lib/lemonade_stand/weather.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(type) ⇒ Weather
Returns a new instance of Weather.
5
6
7
|
# File 'lib/lemonade_stand/weather.rb', line 5
def initialize type
@type = type
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
9
10
11
|
# File 'lib/lemonade_stand/weather.rb', line 9
def method_missing(meth, *args, &blk)
meth.to_s == "#{@type}?"
end
|
Class Method Details
.weather_for(day) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# 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
|
Instance Method Details
#to_s ⇒ Object
13
14
15
|
# File 'lib/lemonade_stand/weather.rb', line 13
def to_s
@type.to_s.split('_').map { |x| x == 'and' ? x : x.capitalize! }.join(' ')
end
|