Created
June 14, 2010 00:15
-
-
Save kotp/437118 to your computer and use it in GitHub Desktop.
Method using Block argument
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> my_method(3, "Sang Shin", {:a => " loves ", :b => " Young Shin"}) {|s| puts s } | |
3 | |
Sang Shin | |
{:a=>" loves ", :b=>" Young Shin"} | |
=> [3, "Sang Shin", {:a=>" loves ", :b=>" Young Shin"}] | |
>> my_method(3, "Sang Shin", {:a => " loves ", :b => " Young Shin"}) {|s| s } | |
=> [3, "Sang Shin", {:a=>" loves ", :b=>" Young Shin"}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_method(int, string, hash, &block) | |
args = int, string, hash | |
args.each do |arg| | |
yield(arg) # This is where your block is yielded. | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment