This is more of a Ruby question than an AWS question. It is about use of
“includes” of the Enumerable mix-in.
I am using the Amazon AWS Ruby (v1) SDK. I want to treat an S3
InstanceCollection as an Enumerable so I can use the ‘length’ and ‘at’
methods on it. According to the docs [1], InstanceCollection inherits
from Collection, which “includes” Enumerable. I’m not sure what that
means exactly, but I get a NoMethodError if I try to use length directly
on an InstanceCollection (see example below). Am I doing something
wrong, or does this sound like a bug in the API (or API docs)?
For the moment I am using the ‘each’ operation to iteratively create a
new Enumerable from the objects in the Collection, but that seems
inefficient and kind of silly.
Is there a way to more directly treat an InstanceCollection as an
Enumerable?
Here’s a sample of my problem:
irb(main):019:0> a=s3.buckets[bucketName].objects
=> AWS::S3::ObjectCollection
irb(main):020:0> a.length
NoMethodError: undefined method length' for <AWS::S3::ObjectCollection>:AWS::S3::ObjectCollection from (irb):20 from /usr/bin/irb:12:in
’
irb(main):021:0>
[1] API docs are at
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/InstanceCollection.html