Created a simple module; can't access it

R

RichardOnRails

Hi,

I posted my simple module and test file at http://www.pastie.org/2025300.
When I run my test under SciTE 1.74 with WinXP-Pro/SP3, I get the
results shown below. In short, I fail trying to include the module
using the name of the module or the name of the file hosting the
module.

Any correction to my misunderstanding would be most appreciated.

Thanks in Advance,
Richard
ruby TestMyMod.rb
RUBY_VERSION = 1.9.2
RUBYLIB = K:\_Projects\Ruby\_Ruby__KeyModules

Attempt to load MyMod
==========
uninitialized constant Object::MyMod
==========

Attempt to load SimpleMod
==========
uninitialized constant Object::SimpleMod
==========

List MyMod container, SimpleMod.rb
Path = K:\_Projects\Ruby\_Ruby__KeyModules\SimpleMod.rb
# SimpleMod.rb
# K:\_Projects\Ruby\_Ruby__KeyModules

module MyMod
def say_hello
puts "Hello from say_hello in MyMod"
end
end
 
S

serialhex

[Note: parts of this message were removed to make it a legal post.]

before one can include a module into a program, one must first have said
module available... so in this case, you should:

##
require 'SimpleMod'
include MyMod # to bring all of MyMod's methods into the current object
##

hex

On Sun, Jun 5, 2011 at 10:25 PM, RichardOnRails <
Hi,

I posted my simple module and test file at http://www.pastie.org/2025300.
When I run my test under SciTE 1.74 with WinXP-Pro/SP3, I get the
results shown below. In short, I fail trying to include the module
using the name of the module or the name of the file hosting the
module.

Any correction to my misunderstanding would be most appreciated.

Thanks in Advance,
Richard

RUBY_VERSION = 1.9.2
RUBYLIB = K:\_Projects\Ruby\_Ruby__KeyModules

Attempt to load MyMod
==========
uninitialized constant Object::MyMod
==========

Attempt to load SimpleMod
==========
uninitialized constant Object::SimpleMod
==========

List MyMod container, SimpleMod.rb
Path = K:\_Projects\Ruby\_Ruby__KeyModules\SimpleMod.rb
# SimpleMod.rb
# K:\_Projects\Ruby\_Ruby__KeyModules

module MyMod
def say_hello
puts "Hello from say_hello in MyMod"
end
end

--


No. That's it. The cool name, that is. We worked very hard on
creating a name that would appeal to the majority of people, and it
certainly paid off: thousands of people are using linux just to be able
to say "OS/2? Hah. I've got Linux. What a cool name". 386BSD made the
mistake of putting a lot of numbers and weird abbreviations into the
name, and is scaring away a lot of people just because it sounds too
technical.
-- Linus Torvalds' follow-up to a question about Linux
 
R

RichardOnRails

[Note:  parts of this message were removed to make it a legal post.]

before one can include a module into a program, one must first have said
module available...  

WOW! It makes perfect sense! Now that you've enlightened me (and I've
applied your advice to confirm its wisdom), I'm amazed that I didn't
see that simple statement in Pickaxe, Black's Rubyist nor in the
multiple on-line posts I Googled.

Thank you very much for that excellent response.

Best wishes,
Richard
 
R

RichardOnRails

[Note:  parts of this message were removed to make it a legal post.]
before one can include a module into a program, one must first have said
module available...  

WOW! It makes perfect sense!  Now that you've enlightened me (and I've
applied your advice to confirm its wisdom),  I'm amazed that I didn't
see that simple statement in Pickaxe, Black's Rubyist nor in the
multiple on-line posts I Googled.

Thank you very much for that excellent response.

Best wishes,
Richard

Hi All,

I have to apologize: I said I checked Pickaxe and it failed to
indicate how to incorporate a foreign module in a Ruby app.

When I reread the Mixins section of Pickaxe vol 2, it plainly
presented the same info that SerialHex generously offered in his post.

Best wishes,
Richard
 

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

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top