Sha256: 864533ead91502445d0b776f0b94784bc297ec36e25ea0fe33ecf2e5f1820696

Contents?: true

Size: 615 Bytes

Versions: 1

Compression:

Stored size: 615 Bytes

Contents

require 'dry-types'

require 'dry/struct/version'
require 'dry/struct/errors'
require 'dry/struct/class_interface'
require 'dry/struct/hashify'

module Dry
  class Struct
    extend ClassInterface

    constructor_type(:permissive)

    def initialize(attributes)
      attributes.each { |key, value| instance_variable_set("@#{key}", value) }
    end

    def [](name)
      public_send(name)
    end

    def to_hash
      self.class.schema.keys.each_with_object({}) do |key, result|
        result[key] = Hashify[self[key]]
      end
    end
    alias_method :to_h, :to_hash
  end
end

require 'dry/struct/value'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-struct-0.2.1 lib/dry/struct.rb