class FFI::Bitmask
def [](*query)
-
(Array
-) -
(Array
-) -
(Integer)
- -
(Integer)
-
Parameters:
-
query
(Array
) -- -
query
(Integer
) -- -
query
(Array
) -- -
query
(Symbol
) --
Overloads:
-
[](query)
-
[](*query)
-
[](query)
-
[](*query)
def [](*query) flat_query = query.flatten raise ArgumentError, "query should be homogeneous, #{query.inspect}" unless flat_query.all? { |o| o.is_a?(Symbol) } || flat_query.all? { |o| o.is_a?(Integer) || o.respond_to?(:to_int) } case flat_query[0] when Symbol flat_query.inject(0) do |val, o| v = @kv_map[o] if v then val |= v else val end end when Integer, ->(o) { o.respond_to?(:to_int) } val = flat_query.inject(0) { |mask, o| mask |= o.to_int } @kv_map.select { |_, v| v & val != 0 }.keys end end