Created
August 7, 2011 12:00
-
-
Save ernie/1130320 to your computer and use it in GitHub Desktop.
Fun with lambdas in 1.9
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
rs = (0..10000).to_a.sample(30) | |
rs.each do |r| | |
case r | |
when :zero?.to_proc then puts "#{r} is zero" | |
when :even?.to_proc then puts "#{r} is even" | |
when :odd?.to_proc then puts "#{r} is odd" | |
else | |
raise 'unpossible' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh that's a neat trick too :)