summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
authorAdam Bard <github@adambard.com>2013-10-09 09:21:58 -0700
committerAdam Bard <github@adambard.com>2013-10-09 09:21:58 -0700
commitdef89743102490d58482f87c801f4686fae2cc42 (patch)
tree4ae4bb4110b9ccb70fa051f0ad51e778f2f54635 /ruby.html.markdown
parentd4c6c8605a47d9b51c41ef6d0cab7e767fa43048 (diff)
parent239595fc5929806b2f8c4d476d9bb383f8b0418e (diff)
Merge pull request #371 from mailopl/master
[ruby/en] 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