Class: Class
- Inherits:
-
Object
- Object
- Class
- Defined in:
- lib/ext/forward_method.rb
Instance Method Summary collapse
- #forward_method(*args) ⇒ Object
-
#forward_methods(*methods, object) ⇒ Object
TODO: Check for arity.
Instance Method Details
#forward_method(*args) ⇒ Object
15 |
# File 'lib/ext/forward_method.rb', line 15 def forward_method(*args) forward_methods(*args) end |
#forward_methods(*methods, object) ⇒ Object
TODO: Check for arity
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/ext/forward_method.rb', line 4 def forward_methods(*methods, object) for method in Array(methods).flatten if method.to_s.end_with?("=") src = "def #{method}(args) raise if #{object}.nil?; #{object}.#{method}(args) end" else src = "def #{method}(*args) #{object}&.#{method}(*args) end" end class_eval(src) end end |