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.



20
21
22
# File 'lib/act_with_booleans.rb', line 20

def act_with_booleans
  @act_with_booleans
end

Instance Method Details

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



22
23
24
25
26
27
28
# File 'lib/act_with_booleans.rb', line 22

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



30
31
32
33
34
# File 'lib/act_with_booleans.rb', line 30

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