1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-11 01:04:10 +02:00

Merge pull request #371 from mailopl/master

[ruby/en] ADD: "&" and "*" use cases in function parameters
This commit is contained in:
Adam Bard
2013-10-09 09:21:58 -07:00

View File

@@ -287,6 +287,18 @@ surround { puts 'hello world' }
# }
# You can pass a block to a function
# "&" marks a reference to a passed block
def guests(&block)
block.call "some_argument"
end
# You can pass a list of arguments, which will be converted into an array
# That's what splat operator ("*") is for
def guests(*array)
array.each { |guest| puts "#{guest}" }
end
# Define a class with the class keyword
class Human