Class: Bitsy::Mask
- Inherits:
-
Object
- Object
- Bitsy::Mask
- Defined in:
- lib/bitsy/mask.rb
Instance Attribute Summary collapse
-
#flag ⇒ Object
readonly
Returns the value of attribute flag.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #^(other) ⇒ Object
-
#initialize(flag, value) ⇒ Mask
constructor
A new instance of Mask.
- #to_i ⇒ Object
- #|(other) ⇒ Object
- #~ ⇒ Object
Constructor Details
#initialize(flag, value) ⇒ Mask
Returns a new instance of Mask.
10 11 12 13 |
# File 'lib/bitsy/mask.rb', line 10 def initialize(flag, value) @flag = flag @value = value end |
Instance Attribute Details
#flag ⇒ Object (readonly)
Returns the value of attribute flag.
4 5 6 |
# File 'lib/bitsy/mask.rb', line 4 def flag @flag end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/bitsy/mask.rb', line 4 def value @value end |
Class Method Details
.with_index(flag, idx) ⇒ Object
6 7 8 |
# File 'lib/bitsy/mask.rb', line 6 def self.with_index(flag, idx) self.new(flag, (1 << idx)) end |
Instance Method Details
#&(other) ⇒ Object
19 20 21 |
# File 'lib/bitsy/mask.rb', line 19 def &(other) self.class.new(combine_flag(other, 'AND'), value & other.to_i) end |
#^(other) ⇒ Object
27 28 29 |
# File 'lib/bitsy/mask.rb', line 27 def ^(other) self.class.new(combine_flag(other, 'XOR'), value ^ other.to_i) end |
#to_i ⇒ Object
15 16 17 |
# File 'lib/bitsy/mask.rb', line 15 def to_i value end |
#|(other) ⇒ Object
23 24 25 |
# File 'lib/bitsy/mask.rb', line 23 def |(other) self.class.new(combine_flag(other, 'OR'), value | other.to_i) end |
#~ ⇒ Object
31 32 33 |
# File 'lib/bitsy/mask.rb', line 31 def ~ self.class.new("NOT_#{flag}".to_sym, ~value) end |