Class: Map::Struct

Inherits:
Object
  • Object
show all
Defined in:
lib/map/struct.rb

Constant Summary collapse

Keys =
lambda{|*keys| keys.flatten!; keys.compact!; keys.map!{|key| key.to_s}}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ Struct

Returns a new instance of Struct.



7
8
9
# File 'lib/map/struct.rb', line 7

def initialize(map)
  @map = map
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/map/struct.rb', line 11

def method_missing(method, *args, &block)
  method = method.to_s
  case method
    when /=$/
      key = method.chomp('=')
      value = args.shift
      @map[key] = value
    else
      key = method
      raise(IndexError, key) unless @map.has_key?(key)
      value = @map[key]
  end
  value.is_a?(Map) ? value.struct : value
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



5
6
7
# File 'lib/map/struct.rb', line 5

def map
  @map
end