class Rudux::Entity
Attributes
id[R]
Public Class Methods
new(hash={})
click to toggle source
# File lib/rudux/entity.rb, line 7 def initialize hash={} unless hash.has_key? :id @id = SecureRandom.uuid.freeze end hash.each do |key, value| value.freeze instance_variable_set("@#{key}", value) end end
Public Instance Methods
copy(hash={})
click to toggle source
# File lib/rudux/entity.rb, line 23 def copy hash={} if hash.empty? self else self.class.new to_hash.merge! hash end end
mutate(hash={})
click to toggle source
# File lib/rudux/entity.rb, line 31 def mutate hash={} if hash.empty? self else hash.keys.each do |key| instance_variable_set("@#{key}", hash[key]) end self end end
to_hash()
click to toggle source
# File lib/rudux/entity.rb, line 17 def to_hash Hash[instance_variables.map{ |key| [key[1..-1].to_sym, instance_variable_get(key)] }] end