# Use of :: operator

**URL:** <https://www.ruby-forum.com/t/use-of-operator/187720>\
**Category:** Rails\
**Created:** [April 28, 2010, 8:48am UTC](https://www.ruby-forum.com/t/use-of-operator/187720 "2010-04-28T08:48:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [April 28, 2010, 8:48am UTC](https://www.ruby-forum.com/t/use-of-operator/187720/1 "2010-04-28T08:48:06Z")

</div>

Hi,

I want to know the use of “::” operator in rails.  
Actually, I have created a module with name “Email” and written a method  
def check\_email(email)  
end  
I want to access this method. So I went to the “ruby/script console” and  
done like as follows:-

“Email::check\_email(‘removed\_email\_address@domain.invalid’)”  
I got an error that “undefined method `check\_email’ for Email:Module”.  
Can anyone tell me what is wrong with my code?  
Also Is it the use of :: operator?

Thanks  
Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [April 28, 2010, 9:00am UTC](https://www.ruby-forum.com/t/use-of-operator/187720/2 "2010-04-28T09:00:43Z")

</div>

Hi,

‘::’ method is used to refer to modules inside a module.

If you define a method inside a module eg)

module Test  
def check  
puts “check”  
end  
end

Then you create a module and define an instance method by the name  
‘check’  
This instance method can only be access by an instance. So it can be  
accessed by instances of classes that have included that module only.  
You can get the method object directly using  
Test.instance\_method(:method\_name), this will give you the UnboundMethod  
obejct which you can then bind to an instance of an object and use it if  
you  
really needed to, other than that I am not sure if you could do anything  
about it directly.

If you want to define a method inside a module and be able to access it  
directly using the module without any inclusion & instantiation then you  
should do the following:

module Test  
def self.check  
puts “check”  
end  
end

Now you can call the method check using _Test.check #=\> check_

On Wed, Apr 28, 2010 at 12:18, Mike D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I got an error that “undefined method `check\_email’ for Email:Module”.  
> You received this message because you are subscribed to the Google G.  
> “Ruby on Rails: Talk” group.  
> To post to this group, send email to removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to  
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–

Thanks & Regards,  
Dhruva S…

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [April 28, 2010, 4:01pm UTC](https://www.ruby-forum.com/t/use-of-operator/187720/3 "2010-04-28T16:01:32Z")

</div>

Thanks Dhruva.  
Now I understood the use of “::” operator.  
Thanks  
Mike

> end
