Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Created January 9, 2011 23:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save igrigorik/772119 to your computer and use it in GitHub Desktop.
Save igrigorik/772119 to your computer and use it in GitHub Desktop.
you can call a proc via: f === :arg!
# 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 should_i_upgrade?
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
should_i_upgrade?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment