Mixins

R

Rong

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 `<main>': uninitialized constant UsefulFeatures
(NameError)

What am I doing wrong?
 
T

Tim Hunter

Rong said:
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 `<main>': uninitialized constant UsefulFeatures
(NameError)

What am I doing wrong?

require's argument is a file name

require 'useful_features'
 
B

Bertram Scharpf

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
 
M

Marc Heiler

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

composition vs 'leaf-class mixins' (vs class inheritance) 5
Python Mixins 9
Mixins 5
Instance Variable in Mixins 1
mixins 2
mysterious behavior of mixins 4
extending a class 2
Constants lookup changes in 1.9.2? 0

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top