Skip to content

Instantly share code, notes, and snippets.

@ryan-allen
Created June 24, 2010 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan-allen/451116 to your computer and use it in GitHub Desktop.
Save ryan-allen/451116 to your computer and use it in GitHub Desktop.
module LumberJack::ExplicitContext
def with(object)
raise "need an object" if not object
yield(object)
object
end
end
include LumberJack::ExplicitContext
sites = with(Array.new) do |sites|
sites << :flashden
sites << :audiojungle
sites << with(Hash.new) do |themeforest|
themeforest[:name] = 'ThemeForest'
themeforest[:url] = 'http://themeforest.net'
themeforest[:top_authors] = with(Array.new) do |top_authors|
top_authors << :john
top_authors << :ryan
top_authors << :glen
end
end
end
puts sites.inspect # [:flashden, :audiojungle, {:top_authors=>[:john, :ryan, :glen], :name=>"ThemeForest", :url=>"http://themeforest.net"}]
module LumberJack::ImplicitContext
def with(object, &block)
raise "need an object" if not object
object.instance_eval(&block)
object
end
end
include LumberJack::ImplicitContext
sites = with(Array.new) do
push :flashden
push :audiojungle
push(with(Hash.new) do
self[:name] = 'ThemeForest'
self[:url] = 'http://themeforest.net'
self[:top_authors] = with(Array.new) do
push :john
push :ryan
push :glen
end
end)
end
puts sites.inspect # [:flashden, :audiojungle, {:top_authors=>[:john, :ryan, :glen], :name=>"ThemeForest", :url=>"http://themeforest.net"}]
Which one is better?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment