Skip to content

Instantly share code, notes, and snippets.

@postmodern
Created April 4, 2011 00:45
Show Gist options
  • Save postmodern/900981 to your computer and use it in GitHub Desktop.
Save postmodern/900981 to your computer and use it in GitHub Desktop.
implicit splat and explicit splat in Ruby 1.9
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