Class: Bytepack::CustomData

Inherits:
Struct
  • Object
show all
Defined in:
lib/bytepack/custom_data.rb

Class Method Summary collapse

Methods inherited from Struct

classifyDataType, config, packingDataType, single_type_array?, testpacking

Class Method Details

.code_by_struct(struct) ⇒ Object



26
27
28
# File 'lib/bytepack/custom_data.rb', line 26

def code_by_struct(struct)
  struct::TYPE_CODE if struct < Struct
end

.inherited(child) ⇒ Object



7
8
9
# File 'lib/bytepack/custom_data.rb', line 7

def inherited(child)
  @subclasses << child
end

.struct_by_code(code) ⇒ Object



30
31
32
# File 'lib/bytepack/custom_data.rb', line 30

def struct_by_code(code)
  subclasses {|child| child::TYPE_CODE == code}
end

.struct_by_ruby_type(val) ⇒ Object



22
23
24
# File 'lib/bytepack/custom_data.rb', line 22

def struct_by_ruby_type(val)
  subclasses {|child| val.is_a?(child::RUBY_TYPE)}
end

.subclasses(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/bytepack/custom_data.rb', line 11

def subclasses(&block)
  selected = nil
  @subclasses.each do |child| # .find() is too slow
    if yield(child)
      selected = child
      break
    end
  end
  selected if block_given?
end