Created a simple module; can't access it

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

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 <
[email protected]> wrote:

Thanks in Advance,

module MyMod
def say_hello
puts “Hello from say_hello in MyMod”
end
end

Exit code: 0

Other than the fact Linux has a cool name, could someone explain why I
should use Linux over BSD?

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

On Jun 5, 10:47pm, serialhex [email protected] wrote:

[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

On Jun 6, 8:08am, RichardOnRails
[email protected] wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs