Sha256: c342d0fb070c998f6c86fad3f0cb980a30614e73a55af69b5b6469584194dd51

Contents?: true

Size: 593 Bytes

Versions: 6

Compression:

Stored size: 593 Bytes

Contents

# frozen_string_literal: true

module Attribool
  ##
  # Abstraction of a reader's method name.
  class ReaderName
    ##
    # Instantiate new instance of ReaderName.
    #
    # @param [String, Syumbol] attribute
    #
    # @param [proc, nil, String, Symbol] name
    def initialize(attribute, name)
      @attribute = attribute
      @name = name
    end

    ##
    # Convert instance to a string.
    #
    # @return [String]
    def to_s
      case @name
      when Proc then @name.call(@attribute)
      when nil then "#{@attribute}?"
      else @name.to_s
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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