Class: Hatt::BlankSlateProxy
- Inherits:
-
Object
- Object
- Hatt::BlankSlateProxy
- Defined in:
- lib/hatt/blankslateproxy.rb
Overview
A simple ‘blankslate’ class which is used to avoid namespace polution Provides a proxy to a parent class, in order to allow access to other hatt methods like http service objects
TODO: Figure out if can/should use a BasicObject here. I know it wont work right now because the binding method of Object is needed and not in BasicObject
Instance Method Summary collapse
-
#initialize(parent) ⇒ BlankSlateProxy
constructor
A new instance of BlankSlateProxy.
- #method_missing(method_id, *arguments, &block) ⇒ Object
- #parent_has_method?(name, include_private = false) ⇒ Boolean
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(parent) ⇒ BlankSlateProxy
Returns a new instance of BlankSlateProxy.
9 10 11 |
# File 'lib/hatt/blankslateproxy.rb', line 9 def initialize(parent) @parent = parent end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/hatt/blankslateproxy.rb', line 13 def method_missing(method_id, *arguments, &block) if parent_has_method?(method_id) @parent.send(method_id, *arguments, &block) else super end end |
Instance Method Details
#parent_has_method?(name, include_private = false) ⇒ Boolean
21 22 23 24 25 26 27 |
# File 'lib/hatt/blankslateproxy.rb', line 21 def parent_has_method?(name, include_private = false) if include_private @parent.methods.include?(name.to_sym) else @parent.public_methods.include?(name.to_sym) end end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
29 30 31 |
# File 'lib/hatt/blankslateproxy.rb', line 29 def respond_to_missing?(name, include_private = false) parent_has_method?(name, include_private) || super end |