Created
January 6, 2012 22:58
-
-
Save jeffreyiacono/1572843 to your computer and use it in GitHub Desktop.
fun with splat in ruby
This file contains hidden or 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
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