Class: Rubeetup::ResponseWrapper
- Inherits:
-
Object
- Object
- Rubeetup::ResponseWrapper
- Defined in:
- lib/rubeetup/response_wrapper.rb
Overview
Simple wrapper to allow the use of method missing in order provide fancier RequestResponse’s attributes access.
Instance Method Summary collapse
-
#initialize(data) ⇒ ResponseWrapper
constructor
A new instance of ResponseWrapper.
-
#method_missing(name, *args) ⇒ Object
It captures messages passed on this object, and only responds to messages for which the @hash can provide a non-nil value.
Constructor Details
#initialize(data) ⇒ ResponseWrapper
Returns a new instance of ResponseWrapper.
10 11 12 |
# File 'lib/rubeetup/response_wrapper.rb', line 10 def initialize(data) @hash = data end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
It captures messages passed on this object, and only responds to messages for which the @hash can provide a non-nil value.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubeetup/response_wrapper.rb', line 18 def method_missing(name, *args) if name == :[] key = args.first @hash.include?(key) ? @hash[key] : super elsif @hash.include? name @hash[name] else super end end |