Sha256: 7f93d5fdb16ff2ac7c82b449c93c1be7e02acbd7a9c2bfdbacd2e074fd29f9b2

Contents?: true

Size: 735 Bytes

Versions: 10

Compression:

Stored size: 735 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 = STRICT.kind_of(::Hash, arg)

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

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kind-5.10.0 lib/kind/immutable_attributes/reader.rb
kind-5.9.0 lib/kind/immutable_attributes/reader.rb
kind-5.8.1 lib/kind/immutable_attributes/reader.rb
kind-5.8.0 lib/kind/immutable_attributes/reader.rb
kind-5.7.0 lib/kind/immutable_attributes/reader.rb
kind-5.6.0 lib/kind/immutable_attributes/reader.rb
kind-5.5.0 lib/kind/immutable_attributes/reader.rb
kind-5.4.1 lib/kind/immutable_attributes/reader.rb
kind-5.4.0 lib/kind/immutable_attributes/reader.rb
kind-5.3.0 lib/kind/immutable_attributes/reader.rb