Class: RestCore::Smash
- Inherits:
-
Object
- Object
- RestCore::Smash
- Defined in:
- lib/rest-core/util/smash.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #==(rhs) ⇒ Object
- #[](*keys) ⇒ Object
-
#initialize(data) ⇒ Smash
constructor
A new instance of Smash.
Constructor Details
#initialize(data) ⇒ Smash
Returns a new instance of Smash.
5 6 7 |
# File 'lib/rest-core/util/smash.rb', line 5 def initialize data self.data = data end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg, *args, &block) ⇒ Object (private)
34 35 36 37 38 39 40 |
# File 'lib/rest-core/util/smash.rb', line 34 def method_missing msg, *args, &block if data.respond_to?(msg) data.public_send(msg, *args, &block) else super end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/rest-core/util/smash.rb', line 4 def data @data end |
Instance Method Details
#==(rhs) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rest-core/util/smash.rb', line 21 def == rhs if rhs.kind_of?(RestCore::Smash) data == rhs.data else data == rhs end end |
#[](*keys) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rest-core/util/smash.rb', line 9 def [] *keys keys.inject(data) do |r, k| if r.respond_to?(:key) && r.key?(k) r[k] elsif r.respond_to?(:[]) r[k] else return nil # stop here end end end |