Class: Bytemapper::Shape
- Inherits:
-
Hash
- Object
- Hash
- Bytemapper::Shape
- Includes:
- Flattenable, Nameable
- Defined in:
- lib/bytemapper/shape.rb
Instance Attribute Summary collapse
-
#hooks ⇒ Object
Returns the value of attribute hooks.
Attributes included from Nameable
Instance Method Summary collapse
- #[]=(k, v) ⇒ Object
- #hook(&block) ⇒ Object
-
#initialize ⇒ Shape
constructor
A new instance of Shape.
- #size ⇒ Object
Methods included from Flattenable
Constructor Details
#initialize ⇒ Shape
Returns a new instance of Shape.
25 26 27 28 |
# File 'lib/bytemapper/shape.rb', line 25 def initialize super @hooks = [] end |
Instance Attribute Details
#hooks ⇒ Object
Returns the value of attribute hooks.
23 24 25 |
# File 'lib/bytemapper/shape.rb', line 23 def hooks @hooks end |
Instance Method Details
#[]=(k, v) ⇒ Object
30 31 32 33 34 |
# File 'lib/bytemapper/shape.rb', line 30 def []=(k,v) super singleton_class.instance_eval { attr_reader k } instance_variable_set("@#{k.to_s}", self[k]) end |
#hook(&block) ⇒ Object
36 37 38 |
# File 'lib/bytemapper/shape.rb', line 36 def hook(&block) @hooks << block if block_given? end |
#size ⇒ Object
40 41 42 |
# File 'lib/bytemapper/shape.rb', line 40 def size flatten.values.map(&:size).reduce(:+) end |