Create a gist now

Instantly share code, notes, and snippets.

# ruby 1.9 supports 4 ways to call a proc! ex: f =->n {[:hello, n]}; f[:ruby]; f.call(:ruby); f.(:ruby)
#
# turns out, you can also call a proc via proc === :arg -- which means you can use proc's in when clauses!
# ruby doc: http://ruby-doc.org/ruby-1.9/classes/Proc.html#M001165
#
# ... kudos to @chadfowler for the tip!
#
# (note: works on 1.8.7 as well :-))
def am_i_awesome?
awesome = Proc.new do |version|
case version
when "1.9.2" then true
when "1.8.7" then false
end
end
case RUBY_VERSION
when awesome
puts "congrats, you're awesome"
else
puts "not really, you should: rvm install 1.9.2"
end
end
am_i_awesome?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment