Skip to content

Instantly share code, notes, and snippets.

@kotp
Created June 14, 2010 00:15
Show Gist options
  • Save kotp/437118 to your computer and use it in GitHub Desktop.
Save kotp/437118 to your computer and use it in GitHub Desktop.
Method using Block argument
>> 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"}]
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