Skip to content

Instantly share code, notes, and snippets.

@bakkdoor
Created October 30, 2008 23:26
Show Gist options
  • Save bakkdoor/21170 to your computer and use it in GitHub Desktop.
Save bakkdoor/21170 to your computer and use it in GitHub Desktop.
class Test
def method(text)
if block_given?
yield "#{text} inside a block!"
else
puts "#{text} not in a block and just simply outputted to console."
end
end
end
t = Test.new
t.method("Hello") # => simply outputs the text above via puts
t.method("Hello with a block") do |text|
puts "now my text is different: #{text}" # will output: "now my text is different: Hello with a block inside a block!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment