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)



506
507
508
# File 'lib/amazon/aws.rb', line 506

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.



533
534
535
# File 'lib/amazon/aws.rb', line 533

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.



541
542
543
# File 'lib/amazon/aws.rb', line 541

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.



525
526
527
# File 'lib/amazon/aws.rb', line 525

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.



515
516
517
# File 'lib/amazon/aws.rb', line 515

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