Ruby
A shorter way to declare class constants?
1
2
3
4
5
6
class Report < ActiveRecord::Base
belongs_to :reportable, :polymorphic => true
HITS = 'hits'
UNIQUES = 'uniques'
end
class Report < ActiveRecord::Base
belongs_to :reportable, :polymorphic => true
HITS = 'hits'
UNIQUES = 'uniques'
end
Refactorings
No refactoring yet !
August 14, 2008,
August 14, 2008 20:13,
permalink
2 ratings.
Login to rate!
1
2
3
class Report < ActiveRecord::Base
%w[hits uniques].each { |const| const_set(const.upcase, const) }
end
I added these so I could refer to Report::HITS in the API. There will be more than just hits and uniques, and I'm wondering if there's a shorter way to declare all this, or a more idiomatic way.