Class: Bitmap
- Inherits:
-
Hash
- Object
- Hash
- Bitmap
- Defined in:
- lib/bitmap.rb
Overview
–
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyleft meh. [http://meh.paranoid.pk | [email protected]]
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
++
Defined Under Namespace
Classes: Value
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #all ⇒ Object
-
#initialize(data) ⇒ Bitmap
constructor
A new instance of Bitmap.
Constructor Details
#initialize(data) ⇒ Bitmap
Returns a new instance of Bitmap.
56 57 58 59 |
# File 'lib/bitmap.rb', line 56 def initialize (data) merge!(data) freeze end |
Instance Method Details
#[](*args) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bitmap.rb', line 61 def [] (*args) args.flatten! args.compact! if args.length == 1 && args.first.is_a?(Integer) Value.new(self, args.first, args.first.to_s(2).reverse.chars.each_with_index.map {|bit, index| next if bit.to_i.zero? key("#{bit}#{'0' * index}".to_i(2)) or raise ArgumentError, "unknown bit at #{index}" }.compact) else Value.new(self, args.map {|arg| super(arg) or super(arg.to_s.to_sym) or raise ArgumentError, "unknown symbol #{arg}" }.inject {|a, b| a | b }, args) end end |