Class: OpenHash::BlackHole
- Inherits:
- BasicObject
- Defined in:
- lib/open_hash.rb
Overview
BlackHole Class
Constant Summary collapse
- DELEGATE_REGEX =
/(.+\?)|(to_.+)|(={2,3})\z/.freeze
Instance Method Summary collapse
-
#<<(method_name) ⇒ Object
Append a method name to chain methods.
-
#initialize(ohash, *args) ⇒ BlackHole
constructor
A new instance of BlackHole.
- #inspect ⇒ Object
-
#method_missing(name, *args) ⇒ Object
:nodoc:.
Constructor Details
#initialize(ohash, *args) ⇒ BlackHole
Returns a new instance of BlackHole.
38 39 40 41 |
# File 'lib/open_hash.rb', line 38 def initialize(ohash, *args) @ohash = ohash @chain_methods = args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
:nodoc:
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/open_hash.rb', line 59 def method_missing(name, *args) # :nodoc: case name when /([^=]+)=\z/ last_ohash = @ohash @chain_methods.each do |method_name| last_ohash = if last_ohash.respond_to?(method_name) last_ohash[method_name] else last_ohash[method_name] = ::OpenHash.new end end last_ohash[$1] = args[0] else self << name end end |
Instance Method Details
#<<(method_name) ⇒ Object
Append a method name to chain methods
54 55 56 57 |
# File 'lib/open_hash.rb', line 54 def <<(method_name) @chain_methods << method_name self end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/open_hash.rb', line 49 def inspect "nil" end |