Module: Zippo::BinaryStructure::Base::InstanceMethods
- Defined in:
- lib/zippo/binary_structure/base.rb
Instance Method Summary collapse
Instance Method Details
#convert_to(other) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/zippo/binary_structure/base.rb', line 94 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
77 78 79 80 81 82 83 |
# File 'lib/zippo/binary_structure/base.rb', line 77 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
84 85 86 87 88 89 90 91 92 |
# File 'lib/zippo/binary_structure/base.rb', line 84 def size self.class.structure.fields.map do |field| if field.dependent send field.dependent else field.width end end.inject(&:+) end |