Ruby 1.9 Proc增加了curry方法,可以将Proc进行curry化:
greeting_func = lambda { |name,greeting| puts "#{greeting} #{name}" }.curry
happy_greeting = greeting_func["Happy"]
happy_greeting["New year"]
hello_greeting = greeting_func["Hello"]
hello_greeting["world"]
结合1.9的Proc#===作为call的alias:
weekday = lambda {|day_of_week, time| day_of_week == time.wday}.curry
sunday,monday,tuesday,wednesday,thursday,friday,saturday = (0..6).collect{|i| weekday[i]}
case Time.now
when sunday,saturday
puts "Day of rest"
when monday,tuesday,wednesday,thursday,friday,saturday
puts "Day of work"
end