summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
authorMarcin Wawrzyniak <wawrzyniak.mm@gmail.com>2013-09-29 18:15:16 +0100
committerMarcin Wawrzyniak <wawrzyniak.mm@gmail.com>2013-09-29 18:15:16 +0100
commit239595fc5929806b2f8c4d476d9bb383f8b0418e (patch)
tree18d8415afac4cca32cffc138f77070b0baa9ede4 /ruby.html.markdown
parent42a2263ab1b2d911f6865975e518da91a3b73e0b (diff)
ADD: "&" and "*" use cases in function parameters
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r--ruby.html.markdown12
1 files changed, 12 insertions, 0 deletions
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