Module: BinData::BitFieldFactory

Included in:
BinData
Defined in:
lib/bindata/bits.rb

Overview

Create classes on demand

Instance Method Summary collapse

Instance Method Details

#const_missing(name) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/bindata/bits.rb', line 167

def const_missing(name)
  mappings = {
    /^Bit(\d+)$/    => :big,
    /^Bit(\d+)le$/  => :little,
    /^Sbit(\d+)$/   => [:big, :signed],
    /^Sbit(\d+)le$/ => [:little, :signed]
  }

  mappings.each_pair do |regex, args|
    if regex =~ name.to_s
      nbits = $1.to_i
      return BitField.define_class(name, nbits, *args)
    end
  end

  super(name)
end