Class: BabelBridge::PatternElementHash
- Inherits:
-
Object
- Object
- BabelBridge::PatternElementHash
- Defined in:
- lib/babel_bridge/pattern_element_hash.rb
Overview
hash which can be used declaratively
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ PatternElementHash
constructor
A new instance of PatternElementHash.
- #inspect ⇒ Object
-
#method_missing(method_name, *args) ⇒ Object
method_name is a symbol.
Constructor Details
#initialize ⇒ PatternElementHash
Returns a new instance of PatternElementHash.
6 7 8 |
# File 'lib/babel_bridge/pattern_element_hash.rb', line 6 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
15 16 17 18 19 20 |
# File 'lib/babel_bridge/pattern_element_hash.rb', line 15 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
#hash ⇒ Object
Returns the value of attribute hash.
4 5 6 |
# File 'lib/babel_bridge/pattern_element_hash.rb', line 4 def hash @hash end |
Instance Method Details
#[](key) ⇒ Object
12 |
# File 'lib/babel_bridge/pattern_element_hash.rb', line 12 def [](key) @hash[key] end |
#[]=(key, value) ⇒ Object
13 |
# File 'lib/babel_bridge/pattern_element_hash.rb', line 13 def []=(key,value) @hash[key]=value end |
#inspect ⇒ Object
10 |
# File 'lib/babel_bridge/pattern_element_hash.rb', line 10 def inspect; hash.inspect; end |