Skip to content

Instantly share code, notes, and snippets.

@bitops
Created June 12, 2015 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitops/34dde2fcb6d33dd2869f to your computer and use it in GitHub Desktop.
Save bitops/34dde2fcb6d33dd2869f to your computer and use it in GitHub Desktop.
#
# ruby splat destructuring
#
class Bar
def qux
42
end
end
class Example
def self.baz
x = [1, 2, 3]
bar(*x).qux
end
def self.bar(a, b, c)
puts a
puts b
puts c
Bar.new
end
def self.foo(*args)
puts "Example#foo invoked with:"
args.each do |arg|
puts "arg => #{arg}"
end
end
end
Example.baz # prints 1, 2, 3 and returns 42
Example.foo(1,2,3) # prints 1, 2, 3 and return [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment