Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/freshen/helpers/module.rb

Instance Method Summary collapse

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 <<-EOS
			class << self
				def #{attribute}(val=nil)
					val.nil? ? @#{attribute} : @#{attribute} = val
				end
			end
			
			def #{attribute}
				self.class.#{attribute}
			end
		EOS
	end
end