Class: BabelBridge::PatternElementHash

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

Overview

hash which can be used declaratively

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePatternElementHash

Returns a new instance of PatternElementHash.



12
13
14
# File 'lib/pattern_element.rb', line 12

def initialize
  @hash = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

method_name is a symbol



19
20
21
22
23
24
# File 'lib/pattern_element.rb', line 19

def method_missing(method_name, *args)  #method_name is a symbol
  return self if args.length==1 && !args[0] # if nil is provided, don't set anything
  raise "More than one argument is not supported. #{self.class}##{method_name} args=#{args.inspect}" if args.length > 1
  @hash[method_name] = args[0] || true # on the other hand, if no args are provided, assume true
  self
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



10
11
12
# File 'lib/pattern_element.rb', line 10

def hash
  @hash
end

Instance Method Details

#[](key) ⇒ Object



16
# File 'lib/pattern_element.rb', line 16

def [](key) @hash[key] end

#[]=(key, value) ⇒ Object



17
# File 'lib/pattern_element.rb', line 17

def []=(key,value) @hash[key]=value end