Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Created a simple module; can't access it

Reply
Thread Tools

Created a simple module; can't access it

 
 
RichardOnRails
Guest
Posts: n/a
 
      06-06-2011
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

>Exit code: 0

 
Reply With Quote
 
 
 
 
serialhex
Guest
Posts: n/a
 
      06-06-2011
[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 <
> wrote:

> 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
>
> >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

 
Reply With Quote
 
 
 
 
RichardOnRails
Guest
Posts: n/a
 
      06-06-2011
On Jun 5, 10:47*pm, serialhex <serial...@gmail.com> 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
 
Reply With Quote
 
RichardOnRails
Guest
Posts: n/a
 
      06-06-2011
On Jun 6, 8:08*am, RichardOnRails
<RichardDummyMailbox58...@USComputerGurus.com> wrote:
> On Jun 5, 10:47*pm, serialhex <serial...@gmail.com> 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


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
aspnet.mdf file still is created even though i created a custom provider? Sunfire ASP .Net 1 11-10-2007 04:30 AM
OleDbDataAdapter created in code behaves differently from one created by wizard. tom c ASP .Net 6 09-06-2006 04:46 PM
are the objects created in the stack guarranted to have been created? jimjim C++ 12 06-03-2005 12:57 PM
IP Conflict . . . (or the Heavens created networking, hell created DHCP) dumbrock NZ Computing 4 10-21-2004 04:57 PM
schemalocation entry in XML created by castor created sources? Ulf Heyder XML 0 10-16-2003 02:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57