1

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,...)

Community
  • 1
  • 1
dormitkon
  • 2,526
  • 4
  • 39
  • 60
  • Duplicate: http://stackoverflow.com/questions/3009477/what-is-rubys-double-colon-all-about. – Blender Mar 20 '11 at 14:41
  • "Simple ruby ... question" is not a very helpful title. 1) Don't describe how difficult the question is in the title. 2) Everything in Stack Overflow is a question, so saying that it's a question is redundant. So all the title tells us is that it's about Ruby syntax. – Andrew Grimm Mar 20 '11 at 22:29

2 Answers2

5

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.

Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
3

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.

Augusto
  • 28,839
  • 5
  • 58
  • 88