Sha256: 8fcb41fd6a0de2f03ae10caf662101a48db3eb9edb59b8e6d008d5f064b84a54
Contents?: true
Size: 834 Bytes
Versions: 3
Compression:
Stored size: 834 Bytes
Contents
# frozen_string_literal: true module Hahamut module Support # Define attributes API module Attributes class << self def included(other) other.extend ClassMethods end end # Define attribute class module ClassMethods def attribute(name, type) name = name.to_sym klass = Attribute.const_get(type.to_s.capitalize) define_method name do @attributes[name]&.value end define_method "#{name}=" do |value| @attributes ||= {} @attributes[name] = klass.new(value) end end end attr_reader :attributes def assign_attributes(attributes) attributes.each do |attr, value| send("#{attr}=", value) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hahamut-0.1.2 | lib/hahamut/support/attributes.rb |
hahamut-0.1.1 | lib/hahamut/support/attributes.rb |
hahamut-0.1.0 | lib/hahamut/support/attributes.rb |