1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-02-06 16:28:52 +01: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
commit def8974310

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