Sha256: 9257ee5445a3579628eb7ad0e463fd99b99c1bc09e7661cf102ffa16c74784a6

Contents?: true

Size: 729 Bytes

Versions: 1

Compression:

Stored size: 729 Bytes

Contents

# frozen_string_literal: true

require 'kind/basic'
require 'kind/__lib__/attributes'

module Kind
  module ImmutableAttributes

    module Reader
      def self.included(base)
        base.send(:attr_reader, :attributes)
      end

      def attribute?(name)
        self.class.__attributes__.key?(name.to_sym)
      end

      def attribute(name)
        @attributes[name.to_sym]
      end

      def attribute!(name)
        @attributes.fetch(name.to_sym)
      end

      def with_attribute(name, value)
        self.class.new(@_____attrs.merge(name.to_sym => value))
      end

      def with_attributes(arg)
        hash = KIND.of!(::Hash, arg)

        self.class.new(@_____attrs.merge(hash))
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kind-5.2.0 lib/kind/immutable_attributes/reader.rb