Sha256: 852081de57ca0eaaa16519c4e85dbb12f22360fe8f10fa809f2474225bb71204

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Attribool
  ##
  # Abstraction for an attribute to determine its name, reader, writer, and
  # instance variable name.
  class Attribute
    ##
    # The name of the attribute, without the leading "@".
    #
    # @return [String]
    attr_reader :name

    ##
    # The name of the instance variable for the attribute, with the leading "@".
    #
    # @return [String]
    attr_reader :ivar

    ##
    # The name of the reader for the attribute.
    #
    # @return [String]
    attr_reader :reader

    ##
    # The name of the writer for the attribute.
    #
    # @return [String]
    attr_reader :writer

    ##
    # Create an Attribute. The attribute can either be a String or a Symbol.
    #
    # @param [String, Symbol] attribute
    #
    # @param [String, Symbol, Proc, nil] reader_name
    def initialize(attribute, reader_name = nil)
      attribute.to_s.then do |a|
        @name = a
        @ivar = "@#{a}"
        @reader = Attribool::ReaderName.new(name, reader_name).to_s
        @writer = "#{name}="
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
attribool-2.0.5 lib/attribool/attribute.rb
attribool-2.0.4 lib/attribool/attribute.rb
attribool-2.0.3 lib/attribool/attribute.rb
attribool-2.0.2 lib/attribool/attribute.rb
attribool-2.0.1 lib/attribool/attribute.rb
attribool-2.0.0 lib/attribool/attribute.rb