Module: Glossarist::Utilities::BooleanAttributes::ClassMethods

Defined in:
lib/glossarist/utilities/boolean_attributes.rb

Instance Method Summary collapse

Instance Method Details

#register_boolean_attribute(attribute) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/glossarist/utilities/boolean_attributes.rb', line 21

def register_boolean_attribute(attribute)
  attr_reader attribute

  define_method("#{attribute}=") do |value|
    instance_variable_set("@#{attribute}", !!value)
  end

  define_method("#{attribute}?") do
    !!instance_variable_get("@#{attribute}")
  end
end

#register_boolean_attributes(attributes) ⇒ Object



15
16
17
18
19
# File 'lib/glossarist/utilities/boolean_attributes.rb', line 15

def register_boolean_attributes(attributes)
  attributes.each do |attribute|
    register_boolean_attribute(attribute)
  end
end