Skip to content

Instantly share code, notes, and snippets.

@joho
Forked from ryan-allen/with.rb
Created November 18, 2008 03:47
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 joho/26034 to your computer and use it in GitHub Desktop.
Save joho/26034 to your computer and use it in GitHub Desktop.
# DRY temporary variables that require single use only, without assignment... seems
# useful for configuration files perhaps? urgh.
class Object
def scoped_variable(*objects)
yield(objects)
end
alias scoped_variable scoped_variables
end
@reports = []
scoped_variable 'Sales' do |group|
@reports << Report.new(:name => 'First', :group => group)
@reports << Report.new(:name => 'Second', :group => group)
@reports << Report.new(:name => 'Third', :group => group)
end
scoped_variables 'Traffic', 'Ninjas' do |group, assassin|
@reports << Report.new(:name => 'Fourth', :group => group, :assassin)
@reports << Report.new(:name => 'Fifth', :group => group, :assassin)
@reports << Report.new(:name => 'Sixth', :group => group, :assassin)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment