# Mixins

**URL:** <https://www.ruby-forum.com/t/mixins/175107>\
**Category:** Ruby\
**Created:** [September 8, 2009, 6:40am UTC](https://www.ruby-forum.com/t/mixins/175107 "2009-09-08T06:40:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@rgreen](https://www.ruby-forum.com/u/rgreen)\
**Post date:** [September 8, 2009, 6:40am UTC](https://www.ruby-forum.com/t/mixins/175107/1 "2009-09-08T06:40:53Z")

</div>

I have the following code separated in 2 files.

module UsefulFeatures

def class\_name  
self.class.to\_s  
end  
end

* * *

require UsefulFeatures

class Person  
include UsefulFeatures  
end

x = Person.new  
puts x.class\_name

Every time I try to run this I get the following error:  
Test2.rb:1:in `’: uninitialized constant UsefulFeatures  
(NameError)

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![rgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@rgreen](https://www.ruby-forum.com/u/rgreen)\
**Post date:** [September 8, 2009, 8:41am UTC](https://www.ruby-forum.com/t/mixins/175107/2 "2009-09-08T08:41:29Z")

</div>

Rong wrote:

> Every time I try to run this I get the following error:  
> Test2.rb:1:in `’: uninitialized constant UsefulFeatures  
> (NameError)
> 
> What am I doing wrong?

require’s argument is a file name

require ‘useful\_features’

---

<div class="post-metadata">

**Author:** ![rgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@rgreen](https://www.ruby-forum.com/u/rgreen)\
**Post date:** [September 8, 2009, 8:46am UTC](https://www.ruby-forum.com/t/mixins/175107/3 "2009-09-08T08:46:10Z")

</div>

Nevermind. I found it.

---

<div class="post-metadata">

**Author:** ![rgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@rgreen](https://www.ruby-forum.com/u/rgreen)\
**Post date:** [September 8, 2009, 2:15pm UTC](https://www.ruby-forum.com/t/mixins/175107/4 "2009-09-08T14:15:08Z")

</div>

Hi,

Am Dienstag, 08. Sep 2009, 15:45:28 +0900 schrieb Rong:

> Nevermind. I found it.

Sorry, this information is not very helpful. Next time please post  
the solution in case somebody googles for it.

Bertram

---

<div class="post-metadata">

**Author:** ![rgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@rgreen](https://www.ruby-forum.com/u/rgreen)\
**Post date:** [September 8, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/mixins/175107/5 "2009-09-08T16:34:08Z")

</div>

> Sorry, this information is not very helpful. Next time please post  
> the solution in case somebody googles for it.

But the solution is quite easy - he did not require the file properly,  
else the constant would be known.
