Created
November 18, 2008 03:56
-
-
Save joho/26042 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
# DRY temporary variables that require single use only, without assignment... seems | |
# useful for configuration files perhaps? urgh. | |
class Object | |
def with(object) | |
yield(object) | |
end | |
end | |
@reports = [] | |
with '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 | |
with 'Traffic' do |group| | |
@reports << Report.new(:name => 'Fourth', :group => group) | |
@reports << Report.new(:name => 'Fifth', :group => group) | |
@reports << Report.new(:name => 'Sixth', :group => group) | |
end | |
# this is less typing. | |
begin | |
group = 'Traffic' | |
@reports << Report.new(:name => 'Fourth', :group => group) | |
@reports << Report.new(:name => 'Fifth', :group => group) | |
@reports << Report.new(:name => 'Sixth', :group => group) | |
end | |
# even less | |
@reports += %w(Seventh Eighth Ninth).collect { |name| Report.new(:name => name, :group => 'Traffic') } | |
# removing obvious redundancy | |
@reports += %w(Seven Eigh Nin).collect { |name| Report.new(:name => "#{name}th", :group => 'Traffic') } | |
# with rails magic | |
@reports += (7..9).collect{|i| Report.new(:name => i.ordinalize, :group => 'Traffic')} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment