Bitmask
Bitmask extends the Integer class to allow for easy manipulation of a number as a bit field.
0xb0100.clear_bit(3) #=> 0
Methods
- bit?
- bit_set?
- bitmask?
- cast_from
- clear_bit
- clear_bitmask
- set_bit
- set_bitmask
- test_bit
- test_bitmask
- to_json
Public Class methods
[ show source ]
# File lib/facets/more/typecast.rb, line 144 def cast_from(object, options={}) retval = super return retval unless retval == nil return object.to_i if object.respond_to? :to_i end
Public Instance methods
Alias for test_bit
Alias for test_bit
Alias for test_bitmask
[ show source ]
# File lib/facets/more/bitmask.rb, line 41 def clear_bit(bit) mask = (1 << bit) self & ~mask end
[ show source ]
# File lib/facets/more/bitmask.rb, line 46 def clear_bitmask(mask) self & ~mask end
[ show source ]
# File lib/facets/more/bitmask.rb, line 32 def set_bit(bit) mask = (1 << bit) self | mask end
[ show source ]
# File lib/facets/more/bitmask.rb, line 37 def set_bitmask(mask) self | mask end
[ show source ]
# File lib/facets/more/bitmask.rb, line 50 def test_bit(bit) mask = (1 << bit) (self & mask) != 0 end
This method is also aliased as
bitmask?
[ show source ]
# File lib/facets/more/bitmask.rb, line 57 def test_bitmask(mask) (self & mask) != 0 end
[ show source ]
# File lib/facets/more/json.rb, line 585 def to_json(*) to_s end