Module: Zippo::BinaryStructure::Base::InstanceMethods
- Defined in:
- lib/zippo/binary_structure/base.rb
Instance Method Summary collapse
Instance Method Details
#convert_to(other) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/zippo/binary_structure/base.rb', line 96 def convert_to(other) other.default.tap do |obj| self.class.common_fields_with(other).each do |field| obj.instance_variable_set "@#{field}", send(field) end end end |
#defaults ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/zippo/binary_structure/base.rb', line 78 def defaults self.class.structure.fields.each do |field| instance_variable_set "@#{field.name}", field.[:default] if field.[:default] instance_variable_set "@#{field.name}", field.[:signature] if field.[:signature] end self end |
#size ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/zippo/binary_structure/base.rb', line 86 def size self.class.structure.fields.map do |field| if field.dependent send field.dependent else field.width end end.reduce(&:+) end |