Possible Duplicate:
What is Ruby's double-colon (::) all about?
Can you explain me, what two dots ::
in ruby means?
Explain me on this example:
AWS::S3::Bucket.find(BUCKET).objects
What is here ASW, what S3, and what is Bucket (I mean, classes, packets, objects,...)
Here is the exact code that you are using under the hood:
https://github.com/marcel/aws-s3/blob/master/lib/aws/s3/bucket.rb
As you can see, there are nested modules/classes:
module AWS
module S3
class Bucket < Base
end
end
end
So:
- AWS is a module.
- S3 is a module.
- Bucket is a class.
The class Bucket is nested inside the module S3 which is nested inside the module AWS.
A Module is basically a bundle of methods/constants, but they differ from classes in the sense where they can't have instances. You use that a lot in order to refactor your code and to better design it. More information on Modules here.
The :: is used to refer to the nested modules/classes. It's a kind of resolution operator, that helps you reach your nested modules/classes/constants by knowing their paths.
It's a ruby module. A module is a container of classes, and it's used to separate the namespace, it's similar (in a way) to java packages.
精彩评论