Module: Ikra::Types::ZipStructType::ZipStruct
- Defined in:
- lib/types/types/struct_type.rb
Overview
A module that provides array-like functionality for FFI Struct types.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
127 128 129 |
# File 'lib/types/types/struct_type.rb', line 127 def self.included(base) base.include(Enumerable) end |
Instance Method Details
#[](index) ⇒ Object
131 132 133 134 |
# File 'lib/types/types/struct_type.rb', line 131 def [](index) # Out of bounds: returns nil return super(:"field_#{index}") end |
#[]=(index, value) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/types/types/struct_type.rb', line 136 def []=(index, value) # TODO: What should we do if the type of a field changes? # Fill up missing slots with `nil` for id in (@fields.size)..index super(:"field_{id}", nil) end super(:"field_{index}", value) return value end |
#each(&block) ⇒ Object
148 149 150 151 152 |
# File 'lib/types/types/struct_type.rb', line 148 def each(&block) for index in 0...(@fields.size) yield(self[index]) end end |