Sha256: 48c8c92376abd43980489e082c6d8733e7dabce015910d4e891c73c42c9f738e

Contents?: true

Size: 500 Bytes

Versions: 4

Compression:

Stored size: 500 Bytes

Contents

# frozen_string_literal: true

# (c) Copyright 2021 Ribose Inc.
#

module Glossarist
  class Model
    def initialize(attributes = {})
      attributes.each_pair { |k, v| set_attribute(k, v) }
    end

    def set_attribute(name, value)
      public_send("#{name}=", value)
    rescue NoMethodError
      raise ArgumentError, "#{self.class.name} does not have " +
        "attribute #{name} defined or the attribute is read only."
    end

    def self.from_h(hash)
      new(hash)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
glossarist-0.2.0 lib/glossarist/model.rb
glossarist-0.1.2 lib/glossarist/model.rb
glossarist-0.1.1 lib/glossarist/model.rb
glossarist-0.1.0 lib/glossarist/model.rb