Class: Amazon::AWS::AWSArray
- Inherits:
-
Array
- Object
- Array
- Amazon::AWS::AWSArray
- Defined in:
- lib/ruby-paa/aws.rb
Overview
Everything we get back from AWS is transformed into an array. Many of these, however, have only one element, because the corresponding XML consists of a parent element containing only a single child element.
This class consists solely to allow single element arrays to pass a method call down to their one element, thus obviating the need for lots of references to foo[0]
in user code.
For example, the following:
items = resp.item_search_response[0].items[0].item
can be reduced to:
items = resp.item_search_response.items.item
Instance Method Summary collapse
-
#==(other) ⇒ Object
In the case of a single-element array, compare the first element with other.
-
#=~(other) ⇒ Object
In the case of a single-element array, perform a pattern match on the first element against other.
-
#to_i ⇒ Object
In the case of a single-element array, return the first element, converted to an Integer.
-
#to_s ⇒ Object
(also: #to_str)
In the case of a single-element array, return the first element, converted to a String.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *params) ⇒ Object (private)
554 555 556 |
# File 'lib/ruby-paa/aws.rb', line 554 def method_missing(method, *params) self.size == 1 ? self[0].send( method, *params ) : super end |
Instance Method Details
#==(other) ⇒ Object
In the case of a single-element array, compare the first element with other.
581 582 583 |
# File 'lib/ruby-paa/aws.rb', line 581 def ==(other) # :nodoc: self.size == 1 ? self[0].to_s == other : super end |
#=~(other) ⇒ Object
In the case of a single-element array, perform a pattern match on the first element against other.
589 590 591 |
# File 'lib/ruby-paa/aws.rb', line 589 def =~(other) # :nodoc: self.size == 1 ? self[0].to_s =~ other : super end |
#to_i ⇒ Object
In the case of a single-element array, return the first element, converted to an Integer.
573 574 575 |
# File 'lib/ruby-paa/aws.rb', line 573 def to_i # :nodoc: self.size == 1 ? self[0].to_i : super end |
#to_s ⇒ Object Also known as: to_str
In the case of a single-element array, return the first element, converted to a String.
563 564 565 |
# File 'lib/ruby-paa/aws.rb', line 563 def to_s # :nodoc: self.size == 1 ? self[0].to_s : super end |