Created
October 30, 2008 23:26
-
-
Save bakkdoor/21170 to your computer and use it in GitHub Desktop.
This file contains 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
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