Class: Mapping

Inherits:
Object show all
Defined in:
lib/Mapping.rb

Overview

TODO I’m not sure I like this approach? - maybe just a hash would be clearer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Mapping

Returns a new instance of Mapping.



6
7
8
9
# File 'lib/Mapping.rb', line 6

def initialize(hash={})
  super()
  @hash = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

TODO Come back to this and include responds_to etc stackoverflow.com/questions/291132/method-missing-gotchas-in-ruby



21
22
23
24
# File 'lib/Mapping.rb', line 21

def method_missing(sym, *args, &block)
  return @hash.send(sym, *args, &block) if @hash.respond_to?(sym)
  super(sym, *args, &block)
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



4
5
6
# File 'lib/Mapping.rb', line 4

def hash
  @hash
end

Instance Method Details

#merge(mapping) ⇒ Object



15
16
17
# File 'lib/Mapping.rb', line 15

def merge(mapping)
  return Mapping.new(@hash.merge(mapping.hash))
end

#valuesObject



11
12
13
# File 'lib/Mapping.rb', line 11

def values
  return MappingValues.new(@hash.values)
end