Class: Amazon::AWS::AWSArray

Inherits:
Array
  • Object
show all
Defined in:
lib/amazon/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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *params) ⇒ Object (private)



547
548
549
# File 'lib/amazon/aws.rb', line 547

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.



574
575
576
# File 'lib/amazon/aws.rb', line 574

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.



582
583
584
# File 'lib/amazon/aws.rb', line 582

def =~(other)  # :nodoc:
  self.size == 1 ? self[0].to_s =~ other : super
end

#to_iObject

In the case of a single-element array, return the first element, converted to an Integer.



566
567
568
# File 'lib/amazon/aws.rb', line 566

def to_i  # :nodoc:
  self.size == 1 ? self[0].to_i : super
end

#to_sObject Also known as: to_str

In the case of a single-element array, return the first element, converted to a String.



556
557
558
# File 'lib/amazon/aws.rb', line 556

def to_s  # :nodoc:
  self.size == 1 ? self[0].to_s : super
end