Created
April 4, 2011 00:45
-
-
Save postmodern/900981 to your computer and use it in GitHub Desktop.
implicit splat and explicit splat in Ruby 1.9
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
class Command | |
def initialize(path,arguments,env={}) | |
@path = path | |
@arguments = arguments | |
@env = env | |
end | |
def to_ary | |
[@env, @path, @arguments] | |
end | |
end | |
command = Command.new('ls', ['-l', '-a'], {'FOO' => 'bar'}) | |
env, path, arguments = command | |
# Ruby 1.9.2 | |
env # => {"FOO"=>"bar"} | |
path # => "ls" | |
arguments # => ["-l", "-a"] | |
# Ruby 1.8.7 | |
env # => #<Command:0x7fb259f894c8 @env={"FOO"=>"bar"}, @arguments=["-l", "-a"], @path="ls"> | |
path # => nil | |
arguments # => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment