# Referencing a method in a module

**URL:** <https://www.ruby-forum.com/t/referencing-a-method-in-a-module/182829>\
**Category:** Ruby\
**Created:** [February 3, 2010, 12:21pm UTC](https://www.ruby-forum.com/t/referencing-a-method-in-a-module/182829 "2010-02-03T12:21:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scrajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@scrajesh](https://www.ruby-forum.com/u/scrajesh)\
**Post date:** [February 3, 2010, 12:21pm UTC](https://www.ruby-forum.com/t/referencing-a-method-in-a-module/182829/1 "2010-02-03T12:21:58Z")

</div>

Say I have the following:

module Foo

def bar  
puts “Baz”  
end

end

If I want to write about (in some documentation, or a bug report) the  
bar method of the Foo module, what’s the best way of referring to it?  
E.g.,

I have found a bug in Foo::bar  
I have found a bug in Foo.bar  
I have found a bug in the bar method of the Foo module

Or some other way?

Many thanks!

Charles

---

<div class="post-metadata">

**Author:** ![scrajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@scrajesh](https://www.ruby-forum.com/u/scrajesh)\
**Post date:** [February 3, 2010, 12:45pm UTC](https://www.ruby-forum.com/t/referencing-a-method-in-a-module/182829/2 "2010-02-03T12:45:23Z")

</div>

Foo#bar is usually used for instance methods, Foo.bar for class  
methods. In this case I think Foo#bar is correct.

Farrel

---

<div class="post-metadata">

**Author:** ![scrajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@scrajesh](https://www.ruby-forum.com/u/scrajesh)\
**Post date:** [February 3, 2010, 4:18pm UTC](https://www.ruby-forum.com/t/referencing-a-method-in-a-module/182829/3 "2010-02-03T16:18:26Z")

</div>

On 03/02/2010 11:37, Farrel L. wrote:

> Foo#bar is usually used for instance methods, Foo.bar for class  
> methods. In this case I think Foo#bar is correct.

Ah, yes, I think I’ve seen that. And so Foo::Bar would be for a class  
within a module?

Many thanks, Farrel.

Charles

---

<div class="post-metadata">

**Author:** ![scrajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@scrajesh](https://www.ruby-forum.com/u/scrajesh)\
**Post date:** [February 3, 2010, 7:26pm UTC](https://www.ruby-forum.com/t/referencing-a-method-in-a-module/182829/4 "2010-02-03T19:26:21Z")

</div>

On Wed, Feb 3, 2010 at 10:13 AM, Charles R.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 03/02/2010 11:37, Farrel L. wrote:
> 
> > Foo#bar is usually used for instance methods, Foo.bar for class  
> > methods. In this case I think Foo#bar is correct.
> 
> Ah, yes, I think I’ve seen that. And so Foo::Bar would be for a class within  
> a module?

More generally

Foo::Bar

refers to the constant named Bar within the namespace named Foo.

Foo could be either a Module or a Class

The value of Bar could be a Module, a Class, or actually any value

module Foo  
class Bar  
Baz = 42  
end  
module ClassMethods  
end  
end

Foo is a module here,

Foo::Bar is a class

Foo::ClassMethods is a module

Foo:Bar::Baz is an integer.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [Rick DeNatale - Developer - IBM | LinkedIn](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![scrajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@scrajesh](https://www.ruby-forum.com/u/scrajesh)\
**Post date:** [February 4, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/referencing-a-method-in-a-module/182829/5 "2010-02-04T14:43:01Z")

</div>

On 3 February 2010 18:25, Rick DeNatale [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> More generally
> 
> Â Foo::Bar
> 
> refers to the constant named Bar within the namespace named Foo.

Rick, many thanks, your explanation is most illuminating.

Cheers,  
Charles
