Created
January 3, 2011 08:03
-
-
Save deepak/763239 to your computer and use it in GitHub Desktop.
showing how splat operator works
This file contains hidden or 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
| chunk, bacon = *["chunky", "bacon"] | |
| puts "#{chunk} #{bacon}" #=> chunky bacon | |
| *chunk_bacon = "chunky", "bacon" | |
| puts chunk_bacon.inspect #=> ["chunky", "bacon"] | |
| puts Proc.new {|*_| _.inspect }.call([12,20]) #=> "[[12, 20]]" | |
| # can be used to collect multiple arguments in one | |
| puts Proc.new {|*_| _.inspect }.call(12,20) #=> "[12, 20]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment