module BinData::IntFactory

Create classes on demand

Public Instance Methods

const_missing(name) click to toggle source
Calls superclass method
# File lib/bindata/int.rb, line 186
def const_missing(name)
  mappings = {
    /^Uint(\d+)be$/ => [:big,    :unsigned],
    /^Uint(\d+)le$/ => [:little, :unsigned],
    /^Int(\d+)be$/  => [:big,    :signed],
    /^Int(\d+)le$/  => [:little, :signed],
  }

  mappings.each_pair do |regex, args|
    if regex =~ name.to_s
      nbits = $1.to_i
      if nbits > 0 && (nbits % 8).zero?
        return Int.define_class(name, nbits, *args)
      end
    end
  end

  super
end