Module: FFI::DRY::ConstFlagsMap
- Includes:
- ConstMap
- Defined in:
- lib/ffi/dry.rb
Overview
Behaves just like ConstFlags, except that the [nnn] returns a list of names for the flags set on nnn. Name string lookups work same way as ConstFlags.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](arg) ⇒ Object
A flexible lookup.
Methods included from ConstMap
Class Method Details
.included(klass) ⇒ Object
336 337 338 |
# File 'lib/ffi/dry.rb', line 336 def self.included(klass) klass.extend(ConstFlagsMap) end |
Instance Method Details
#[](arg) ⇒ Object
A flexible lookup. Takes ‘arg’ as a Symbol or String as a name to lookup a bit-flag value, or an Integer to lookup a corresponding names for the flags present in it.
343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/ffi/dry.rb', line 343 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 |