Last active
December 16, 2015 04:19
-
-
Save acook/5376269 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
@contents = Hash.new | |
@views = Array.new | |
def content_for identifier, content = nil, &content_block | |
@contents[identifier] = block_given? ? content_block.call : content | |
end | |
def run | |
return false if @views.empty? | |
view_wrapper do |identifier| | |
@contents[identifier] | |
end | |
true | |
end | |
def view_wrapper | |
@views.each do |view| | |
puts eval(view) | |
end | |
end | |
def add_view text | |
@views << %Q{"#{text}"} | |
end | |
#----- | |
content_for :bob do | |
"Little Bobby Fisher" | |
end | |
content_for :sally do | |
"Little Sally Ride" | |
end | |
add_view '#{yield :bob} is so damn cool' | |
add_view '#{yield :sally} is so damn cool' | |
run |
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
1.9.3 (Object#main):0 > run | |
Little Bobby Fisher is so damn cool | |
Little Sally Ride is so damn cool | |
=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment