Class: Bytemapper::Shape

Inherits:
Hash
  • Object
show all
Includes:
Flattenable, Nameable
Defined in:
lib/bytemapper/shape.rb

Instance Attribute Summary collapse

Attributes included from Nameable

#name, #names

Instance Method Summary collapse

Methods included from Flattenable

#flatten

Constructor Details

#initializeShape

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

#hooksObject

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

#sizeObject



40
41
42
# File 'lib/bytemapper/shape.rb', line 40

def size
  flatten.values.map(&:size).reduce(:+)
end