From 239595fc5929806b2f8c4d476d9bb383f8b0418e Mon Sep 17 00:00:00 2001 From: Marcin Wawrzyniak Date: Sun, 29 Sep 2013 18:15:16 +0100 Subject: ADD: "&" and "*" use cases in function parameters --- ruby.html.markdown | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ruby.html.markdown b/ruby.html.markdown index b9ba83cb..8723e18f 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -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 -- cgit v1.2.3