Class: Conformist::HashStruct

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/conformist/hash_struct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ HashStruct

Returns a new instance of HashStruct.



9
10
11
# File 'lib/conformist/hash_struct.rb', line 9

def initialize attributes = {}
  self.attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



29
30
31
# File 'lib/conformist/hash_struct.rb', line 29

def method_missing method, *args, &block
  fetch(method) { super }
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/conformist/hash_struct.rb', line 5

def attributes
  @attributes
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
# File 'lib/conformist/hash_struct.rb', line 19

def == other
  other.class == self.class && attributes == other.attributes
end

#merge(other) ⇒ Object



13
14
15
16
17
# File 'lib/conformist/hash_struct.rb', line 13

def merge other
  self.class.new.tap do |instance|
    instance.attributes = attributes.merge other
  end
end