class ImmutableRecord::Value
Public Class Methods
[](opts)
click to toggle source
# File lib/immutable_record.rb, line 37 def self.[] (opts) new(opts) end
name()
click to toggle source
Calls superclass method
# File lib/immutable_record.rb, line 33 def self.name super || to_s end
new(opts)
click to toggle source
# File lib/immutable_record.rb, line 16 def initialize (opts) missing_keys = self.class::ATTRIBUTES - opts.keys if missing_keys.any? raise ArgumentError, "Missing attribute(s): #{missing_keys.inspect}" end extra_keys = opts.keys - self.class::ATTRIBUTES if extra_keys.any? raise ArgumentError, "Unknown attribute(s): #{extra_keys.inspect}" end self.class::ATTRIBUTES.each do |attr| instance_variable_set("@#{attr}", opts.fetch(attr)) end freeze end
Public Instance Methods
==(other)
click to toggle source
# File lib/immutable_record.rb, line 55 def == (other) other.is_a?(self.class) && __values__ == other.send(:__values__) end
clone(opts={}, &block)
click to toggle source
# File lib/immutable_record.rb, line 41 def clone (opts={}, &block) opts = __attributes__.merge(opts) opts = opts.merge(block.call(opts)) if block_given? self.class.new(opts) end
eql?(other)
click to toggle source
# File lib/immutable_record.rb, line 59 def eql? (other) hash == other.hash end
hash()
click to toggle source
# File lib/immutable_record.rb, line 63 def hash self.class.hash ^ __attributes__.hash end
inspect()
click to toggle source
# File lib/immutable_record.rb, line 51 def inspect to_s end
pretty_print(q)
click to toggle source
# File lib/immutable_record.rb, line 67 def pretty_print (q) name = self.class.name size = name.length + 1 q.group(size, "#{name}[", "]") { q.pp __attributes__ } end
to_s()
click to toggle source
# File lib/immutable_record.rb, line 47 def to_s "#{self.class.name}[#{__attributes__.inspect}]" end
Private Instance Methods
__attributes__()
click to toggle source
# File lib/immutable_record.rb, line 79 def __attributes__ Hash[self.class::ATTRIBUTES.zip(__values__)] end
__values__()
click to toggle source
# File lib/immutable_record.rb, line 75 def __values__ self.class::ATTRIBUTES.map(&method(:public_send)) end