-
-
Save SafeAF/81923c3833a379342d684498200fb4e2 to your computer and use it in GitHub Desktop.
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
# 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