diff options
author | Adam Bard <github@adambard.com> | 2013-10-09 09:21:58 -0700 |
---|---|---|
committer | Adam Bard <github@adambard.com> | 2013-10-09 09:21:58 -0700 |
commit | def89743102490d58482f87c801f4686fae2cc42 (patch) | |
tree | 4ae4bb4110b9ccb70fa051f0ad51e778f2f54635 | |
parent | d4c6c8605a47d9b51c41ef6d0cab7e767fa43048 (diff) | |
parent | 239595fc5929806b2f8c4d476d9bb383f8b0418e (diff) |
Merge pull request #371 from mailopl/master
[ruby/en] ADD: "&" and "*" use cases in function parameters
-rw-r--r-- | ruby.html.markdown | 12 |
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 |