Method: AMT::Utility::BitStruct#initialize

Defined in:
lib/amt/utility/bit_struct.rb

#initialize(value = 0) ⇒ BitStruct

Create a new object. If value is an integer, it is used directly and interpreted bit-wise. If value is an array, it is processed in the following way:

  • symbols are interpreted as boolean fields

  • two-item arrays where the first item is a symbol and the second an integer are interpreted as unsigned or enum fields (depending in which category the symbol falls).



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/amt/utility/bit_struct.rb', line 120

def initialize(value = 0)
  if value.kind_of?(Integer)
    @value = value
  elsif value.kind_of?(Array)
    @value = 0
    value.each do |sym, val|
      if val.nil?
        send("#{sym}!")
      else
        send("#{sym}=", val)
      end
    end
  else
    raise ArgumentError, 'invalid argument type specified'
  end
end