class FinerStruct::Mutable

Public Class Methods

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

Public Instance Methods

==(other) click to toggle source
# File lib/finer_struct/anonymous_mutable.rb, line 26
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_mutable.rb, line 8
def method_missing(method, *arguments)
  if has_attribute?(method)
    @attributes[method]
  elsif is_assigment?(method) && has_attribute?(key_for_assignment(method))
    @attributes[key_for_assignment(method)] = arguments[0]
  else
    super
  end
end
respond_to?(method, include_all = false) click to toggle source
Calls superclass method
# File lib/finer_struct/anonymous_mutable.rb, line 18
def respond_to?(method, include_all = false)
  has_attribute?(method) || super
end
to_hash() click to toggle source
# File lib/finer_struct/anonymous_mutable.rb, line 22
def to_hash
  @attributes.dup
end

Private Instance Methods

has_attribute?(attribute) click to toggle source
# File lib/finer_struct/anonymous_mutable.rb, line 40
def has_attribute?(attribute)
  @attributes && @attributes.has_key?(attribute)
end
is_assigment?(method) click to toggle source
# File lib/finer_struct/anonymous_mutable.rb, line 32
def is_assigment?(method)
  method.to_s.end_with?("=")
end
key_for_assignment(method) click to toggle source
# File lib/finer_struct/anonymous_mutable.rb, line 36
def key_for_assignment(method)
  method.to_s[0..-2].to_sym
end