class FinerStruct::Immutable

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/finer_struct/anonymous_immutable.rb, line 4
def initialize(attributes = {})
  @attributes = attributes.dup.freeze
  freeze
end

Public Instance Methods

==(other) click to toggle source
# File lib/finer_struct/anonymous_immutable.rb, line 25
def ==(other)
  other.class == self.class && other.to_hash == to_hash
end
method_missing(method, *arguments) click to toggle source
Calls superclass method
# File lib/finer_struct/anonymous_immutable.rb, line 9
def method_missing(method, *arguments)
  if has_attribute?(method)
    @attributes[method]
  else
    super
  end
end
respond_to?(method, include_all = false) click to toggle source
Calls superclass method
# File lib/finer_struct/anonymous_immutable.rb, line 17
def respond_to?(method, include_all = false)
  has_attribute?(method) || super
end
to_hash() click to toggle source
# File lib/finer_struct/anonymous_immutable.rb, line 21
def to_hash
  @attributes
end

Private Instance Methods

has_attribute?(attribute) click to toggle source
# File lib/finer_struct/anonymous_immutable.rb, line 31
def has_attribute?(attribute)
  @attributes && @attributes.has_key?(attribute)
end