Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created January 6, 2012 22:58
Show Gist options
  • Save jeffreyiacono/1572843 to your computer and use it in GitHub Desktop.
Save jeffreyiacono/1572843 to your computer and use it in GitHub Desktop.
fun with splat in ruby
def add(a, b)
a + b
end
def say(what, *people)
people.each { |person| puts "#{person}: #{what}" }
end
say "Hello!", "Bob", "Alice"
# Bob: Hello!
# Alice: Hello!
people = ["Bob", "Alice"]
say "Hello!", *people
# Bob: Hello!
# Alice: Hello!
pair = [3, 4]
add *pair
# 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment