Class: Damsel::AttributeSet
- Inherits:
-
Object
- Object
- Damsel::AttributeSet
- Defined in:
- lib/damsel/attribute_set.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
Instance Method Summary collapse
- #<<(attribute) ⇒ Object
- #[](name) ⇒ Object
-
#initialize ⇒ AttributeSet
constructor
A new instance of AttributeSet.
Constructor Details
#initialize ⇒ AttributeSet
Returns a new instance of AttributeSet.
5 6 7 |
# File 'lib/damsel/attribute_set.rb', line 5 def initialize @attrs = {} end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
3 4 5 |
# File 'lib/damsel/attribute_set.rb', line 3 def attrs @attrs end |
Instance Method Details
#<<(attribute) ⇒ Object
9 10 11 |
# File 'lib/damsel/attribute_set.rb', line 9 def <<(attribute) @attrs[attribute.name] = attribute end |
#[](name) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/damsel/attribute_set.rb', line 13 def [](name) return @attrs[name] if @attrs[name] singular = name.to_s.singularize.to_sym return @attrs[singular] if @attrs[singular] plural = name.to_s.pluralize.to_sym return @attrs[plural] if @attrs[plural] raise "unknown attribute: #{name} (#{singular} #{plural})" end |