Module: ActWithBooleans::ClassMethods

Defined in:
lib/act_with_booleans.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#act_with_booleansObject (readonly)

Returns the value of attribute act_with_booleans.



18
19
20
# File 'lib/act_with_booleans.rb', line 18

def act_with_booleans
  @act_with_booleans
end

Instance Method Details

#add_to_booleans(*booleans, origin: nil, **hash) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/act_with_booleans.rb', line 20

def add_to_booleans(*booleans, origin: nil, **hash)
  origin = origin&.to_sym
  init(origin)

  booleans.each { |name| act_with_booleans.add_flag(name, nil) }
  hash.each { |name, pos| act_with_booleans.add_flag(name, pos) }
end

#booleans_mask(*booleans) ⇒ Object



28
29
30
31
32
# File 'lib/act_with_booleans.rb', line 28

def booleans_mask(*booleans)
  booleans.inject(0) { |memo, bool|
    memo | 1 << act_with_booleans.position(bool)
  }
end