Created
September 15, 2011 06:22
-
-
Save myronmarston/1218664 to your computer and use it in GitHub Desktop.
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
$ ruby --version | |
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0] | |
$ ruby splat_args.rb | |
Arguments received by method: | |
arg_1: [1, 2, 3] | |
arg_2: [] | |
Arguments received by class_exec: | |
arg_1: [1, 2, 3] | |
arg_2: [] | |
Arguments received by instance_exec: | |
arg_1: [1, 2, 3] | |
arg_2: [] |
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
$ ruby --version | |
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0] | |
$ ruby splat_args.rb | |
Arguments received by method: | |
arg_1: [1, 2, 3] | |
arg_2: [] | |
Arguments received by class_exec: | |
arg_1: 1 | |
arg_2: [2, 3] | |
Arguments received by instance_exec: | |
arg_1: 1 | |
arg_2: [2, 3] | |
$ rvm use 1.9.3 | |
Using /Users/myron/.rvm/gems/ruby-1.9.3-preview1 | |
$ ruby --version | |
ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-darwin10.8.0] | |
$ ruby splat_args.rb | |
Arguments received by method: | |
arg_1: [1, 2, 3] | |
arg_2: [] | |
Arguments received by class_exec: | |
arg_1: 1 | |
arg_2: [2, 3] | |
Arguments received by instance_exec: | |
arg_1: 1 | |
arg_2: [2, 3] |
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
def foo(arg_1, *arg_2) | |
puts "Arguments received by method:" | |
puts "arg_1: #{arg_1.inspect}" | |
puts "arg_2: #{arg_2.inspect}" | |
end | |
foo([1, 2, 3]) | |
puts | |
Class.class_exec([1, 2, 3]) do |arg_1, *arg_2| | |
puts "Arguments received by class_exec:" | |
puts "arg_1: #{arg_1.inspect}" | |
puts "arg_2: #{arg_2.inspect}" | |
end | |
puts | |
instance_exec([1, 2, 3]) do |arg_1, *arg_2| | |
puts "Arguments received by instance_exec:" | |
puts "arg_1: #{arg_1.inspect}" | |
puts "arg_2: #{arg_2.inspect}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment