Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/freshen/helpers/module.rb
Instance Method Summary collapse
-
#attr_class(*attributes) ⇒ Object
Define static attributes on a class.
Instance Method Details
#attr_class(*attributes) ⇒ Object
Define static attributes on a class.
Example:
>> class BaseTest
>> attr_class :name
>> end
>>
>> class Test < BaseTest
>> name "Test"
>> end
>>
>> test = Test.new
>> test.name
=> "Test"
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/freshen/helpers/module.rb', line 17 def attr_class(*attributes) attributes.each do |attribute| module_eval " class << self\n def \#{attribute}(val=nil)\n val.nil? ? @\#{attribute} : @\#{attribute} = val\n end\n end\n \n def \#{attribute}\n self.class.\#{attribute}\n end\n EOS\n end\nend\n" |