ADD: "&" and "*" use cases in function parameters

This commit is contained in:
Marcin Wawrzyniak 2013-09-29 18:15:16 +01:00
parent 42a2263ab1
commit 239595fc59

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