Skip to content

Instantly share code, notes, and snippets.

@acook
Last active December 16, 2015 04:19
Show Gist options
  • Save acook/5376269 to your computer and use it in GitHub Desktop.
Save acook/5376269 to your computer and use it in GitHub Desktop.
@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
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