Fun with lambdas in 1.9
This file contains 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 :)