Skip to content

Commit

Permalink
Execute around
Browse files Browse the repository at this point in the history
  • Loading branch information
r-glebov committed Mar 6, 2015
1 parent 3fbdec3 commit 0408d7c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
21 changes: 21 additions & 0 deletions debugging_and_expectation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def with_debugging
puts "Got Here!"
result = yield
puts "Result was #{result}"
end

# with_debugging do
# magic_number = (23 - Time.now.hour) * Math::PI
# end

def with_expectation(expected_value)
puts "Running test"
result = yield
if expected_value == result
puts "Passed."
else
puts "Failed\nExpected #{expected_value}, but got #{result}"
end
end

with_expectation(5) { 2 + 2 }
14 changes: 14 additions & 0 deletions execute_around.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def tag(value)
print "<#{value}>"
print yield
print "</#{value}>"
end

tag(:h1) { "Breaking News!" }
tag(:h2) { "Massive Ruby Discovered" }

tag(:ul) do
tag(:li) { "It sparkles!"}
tag(:li) { "It shines!"}
tag(:li) { "It mesmerizes!"}
end

0 comments on commit 0408d7c

Please sign in to comment.