Sha256: 8f70f46bd7b4cc807d4a6f49beb9034c34ae97580310576d53c555dbe7087fc8

Contents?: true

Size: 804 Bytes

Versions: 26

Compression:

Stored size: 804 Bytes

Contents

# frozen_string_literal: true

module Glossarist
  module Utilities
    module BooleanAttributes
      def self.included(base)
        base.extend(ClassMethods)
      end

      def self.extended(base)
        base.extend(ClassMethods)
      end

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

        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
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
glossarist-2.3.0 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.2.1 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.2.0 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.1.0 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.10 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.9 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.8 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.7 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.6 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.5 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.4 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.3 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.2 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.1 lib/glossarist/utilities/boolean_attributes.rb
glossarist-2.0.0 lib/glossarist/utilities/boolean_attributes.rb
glossarist-1.1.0 lib/glossarist/utilities/boolean_attributes.rb
glossarist-1.0.9 lib/glossarist/utilities/boolean_attributes.rb
glossarist-1.0.8 lib/glossarist/utilities/boolean_attributes.rb
glossarist-1.0.7 lib/glossarist/utilities/boolean_attributes.rb
glossarist-1.0.6 lib/glossarist/utilities/boolean_attributes.rb