Module: FFI::DRY::ConstFlagsMap
- Includes:
- ConstMap
- Defined in:
- lib/ffi/dry.rb
Overview
Behaves just like ConstFlags, except that it returns a list of names for the flags. Name string lookups work same way as ConstFlags.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](arg) ⇒ Object
A flexible lookup method for name to bit-flag mappings.
Methods included from ConstMap
Class Method Details
.included(klass) ⇒ Object
350 351 352 |
# File 'lib/ffi/dry.rb', line 350 def self.included(klass) klass.extend(ConstFlagsMap) end |
Instance Method Details
#[](arg) ⇒ Object
A flexible lookup method for name to bit-flag mappings.
359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/ffi/dry.rb', line 359 def [](arg) if arg.is_a? Integer ret = [] if arg == 0 n = list.invert[0] ret << n if n else list.invert.sort.each {|v,n| ret << n if v !=0 and (v & arg) == v } end return ret elsif arg.is_a? String or arg.is_a? Symbol list[arg.to_s.upcase] end end |