Parent

Class Index [+]

Quicksearch

Flt::Support::FlagValues

This class assigns bit-values to a set of symbols so they can be used as flags and stored as an integer.

  fv = FlagValues.new(:flag1, :flag2, :flag3)
  puts fv[:flag3]
  fv.each{|f,v| puts "#{f} -> #{v}"}

Public Class Methods

new(*flags) click to toggle source

The flag symbols must be passed; values are assign in increasing order.

  fv = FlagValues.new(:flag1, :flag2, :flag3)
  puts fv[:flag3]
    # File lib/flt/support.rb, line 21
21:       def initialize(*flags)
22:         @flags = {}
23:         value = 1
24:         flags.each do |flag|
25:           raise InvalidFlagType,"Flags must be defined as symbols or classes; invalid flag: #{flag.inspect}" unless flag.kind_of?(Symbol) || flag.instance_of?(Class)
26:           @flags[flag] = value
27:           value <<= 1
28:         end
29:       end

Public Instance Methods

[](flag) click to toggle source

Get the bit-value of a flag

    # File lib/flt/support.rb, line 32
32:       def [](flag)
33:         v = @flags[flag]
34:         raise InvalidFlagError, "Invalid flag: #{flag}" unless v
35:         v
36:       end
all_flags_value() click to toggle source
    # File lib/flt/support.rb, line 51
51:       def all_flags_value
52:         (1 << size) - 1
53:       end
each(&blk) click to toggle source

Return each flag and its bit-value

    # File lib/flt/support.rb, line 39
39:       def each(&blk)
40:         if blk.arity==2
41:           @flags.to_a.sort_by{|f,v|v}.each(&blk)
42:         else
43:           @flags.to_a.sort_by{|f,v|v}.map{|f,v|f}.each(&blk)
44:         end
45:       end
size() click to toggle source
    # File lib/flt/support.rb, line 47
47:       def size
48:         @flags.size
49:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.