Skip to content

Instantly share code, notes, and snippets.

@ernie
Created August 7, 2011 12:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ernie/1130320 to your computer and use it in GitHub Desktop.
Fun with lambdas in 1.9
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
@dkubb
Copy link

dkubb commented Aug 8, 2011

Oh that's a neat trick too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment