# Class Methods vs Module Methods?

**URL:** <https://www.ruby-forum.com/t/class-methods-vs-module-methods/107156>\
**Category:** Ruby\
**Created:** [June 18, 2007, 5:54pm UTC](https://www.ruby-forum.com/t/class-methods-vs-module-methods/107156 "2007-06-18T17:54:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phphd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eada6e/32.png) [@phphd](https://www.ruby-forum.com/u/phphd)\
**Post date:** [June 18, 2007, 5:54pm UTC](https://www.ruby-forum.com/t/class-methods-vs-module-methods/107156/1 "2007-06-18T17:54:08Z")

</div>

Hello all,

Is there anybody else confused about module methods? Why would you  
create one when you could create a class method that is essentially the  
same thing but with more functionality?

---

<div class="post-metadata">

**Author:** ![phphd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eada6e/32.png) [@phphd](https://www.ruby-forum.com/u/phphd)\
**Post date:** [June 18, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/class-methods-vs-module-methods/107156/2 "2007-06-18T18:31:36Z")

</div>

PHP HD schrieb:

> Hello all,
> 
> Is there anybody else confused about module methods? Why would you  
> create one when you could create a class method that is essentially the  
> same thing but with more functionality?

Because you can “mixin” these methods in classes.  
module Foo  
def test  
puts “Hello!”  
end  
end

class Bar  
include Foo  
end

f = Bar.new  
f.test #=\> Hello!

---

<div class="post-metadata">

**Author:** ![phphd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eada6e/32.png) [@phphd](https://www.ruby-forum.com/u/phphd)\
**Post date:** [June 18, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/class-methods-vs-module-methods/107156/3 "2007-06-18T18:36:37Z")

</div>

On Jun 18, 9:54 am, PHP HD [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there anybody else confused about module methods? Why would you  
> create one when you could create a class method that is essentially the  
> same thing but with more functionality?

Because sometimes you want a namespace for methods, but there’s no  
class that can be instantiated:

module Cupid  
def self.createConnection( person1, person2 )  
# …mysterious details here…  
end  
end

Cupid.createConnection( … )

These may also be utility methods used by ‘instance’ methods in a  
module that will be mixed into one or more other classes.
