Sha256: 8da5e2533a5c6e809b144497b2f780e979dbdb9ee867e21e5a685796401c2f5a

Contents?: true

Size: 584 Bytes

Versions: 1

Compression:

Stored size: 584 Bytes

Contents

module LemonadeStand

  class Weather

    def initialize type
      @type = type
    end

    def method_missing(meth, *args, &blk)
      meth.to_s == "#{@type}?"
    end

    def to_s
      @type.to_s.split('_').map { |x| x == 'and' ? x : x.capitalize! }.join(' ')
    end

    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

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lemonade_stand-0.0.1 lib/lemonade_stand/weather.rb