Method: AMT::Utility::BitStruct.boolean

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

.boolean(index, name, desc = name.to_s) ⇒ Object

Interpret the bit with the index (starting from zero) as boolean flag named name (should be a Symbol). If the bit at the index is 1, the flag is interpreted as true. The optional parameter desc can be used to provide a textual representation of the true state.

This method also adds accessor methods for the property. For example, if the property is called amt_enabled, the created getter method is called #amt_enabled? and the setter method is called #amt_enabled!. Note the trailing question/exclamation marks.

Example usage:

boolean 5, :amt_enabled, 'AMT is enabled'


27
28
29
30
31
32
33
34
35
36
# File 'lib/amt/utility/bit_struct.rb', line 27

def self.boolean(index, name, desc = name.to_s)
  index = (0x1 << index)
  (@boolean ||= []) << [name, desc]
  define_method("#{name}?") do
    @value & index == index
  end
  define_method("#{name}!") do
    @value |= index
  end
end