Created
June 12, 2015 23:25
-
-
Save bitops/34dde2fcb6d33dd2869f to your computer and use it in GitHub Desktop.
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
# | |
# 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