Proc and ===
even = ->(x) { (x % 2) == 0 } # we can use Proc#call even.call(2) even.call(3) # also available to use ===, instead of using Proc#call even === 2 even === 3 # we can use === in case statement as well. fizzbuzz = ->(x) { (x % 3) == 0 && (x % 5) == 0 } fizz = ->(x) { (x % 3) == 0 } buzz = ->(x) { (x % 5) == 0 } (1..100).each do |i| puts case i when fizzbuzz then "fizzbuzz" when buzz then "buzz" when fizz then "fizz" else i end end
learned from RubyTapas#037 introducing more practical use case. it seems there must be a chance to use sometime :)