Module: Attributable
- Defined in:
- lib/attributable.rb,
lib/attributable/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Method Summary collapse
Instance Method Details
#attributes(*without_defaults, **with_defaults) ⇒ Object
4 5 6 7 8 |
# File 'lib/attributable.rb', line 4 def attributes(*without_defaults, **with_defaults) @predefined_attributes ||= {} @predefined_attributes = @predefined_attributes.merge(from(without_defaults, with_defaults)) add_instance_methods(@predefined_attributes) end |
#specialises(clazz) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/attributable.rb', line 10 def specialises(clazz) unless clazz.kind_of? Attributable fail ArgumentError, "specialisation requires a class that extends Attributable" end super_attributes = clazz.new.instance_variable_get(:@attributes) @predefined_attributes ||= {} @predefined_attributes = super_attributes.merge(@predefined_attributes) add_instance_methods(@predefined_attributes) @predefined_attributes end |