Created
September 22, 2008 12:15
-
-
Save kakra/11974 to your computer and use it in GitHub Desktop.
How to apply case-when on lambdas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Proc | |
def ===(*parameters) | |
self.call(*parameters) | |
end | |
end | |
sunday = Proc.new { |time| time.wday == 0 } | |
monday = Proc.new { |time| time.wday == 1 } | |
tuesday = Proc.new { |time| time.wday == 2 } | |
wednesday = Proc.new { |time| time.wday == 3 } | |
thursday = Proc.new { |time| time.wday == 4 } | |
friday = Proc.new { |time| time.wday == 5 } | |
saturday = Proc.new { |time| time.wday == 6 } | |
case Time.now | |
when sunday | |
puts "Faulenzen!" | |
when monday, tuesday | |
puts "Örks, arbeiten. :-(" | |
when wednesday | |
puts "Hälfte geschafft." | |
when thursday | |
puts "Ein Tag noch!" | |
when friday | |
puts "Juhu, bald Wochenende!" | |
when saturday | |
puts "Partytime!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment