[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

irb newbie question

Nicholas Parsons

8/20/2006 2:14:00 PM

Hello All!

I'm new to Ruby and this group. I was hoping that someone could lend
a helping hand involving the irb interpreter packaged with ruby
version 1.8 on Mac OSX. I would like to import or load some classes
that are defined in a separate .rb file on my hard disk into an
interactive session of irb. I tried invoking the load() function
with '~/classes.rb' as a parameter. The interpreter gave me a 'true'
value in response. But when I tried to create an instance of one of
the classes defined in the file I got a undefined class error from
irb. I also tried using the require keyword with the same path in
quotes to load that class file and it produced the same results.

So, can anyone tell me how to import those class definition ruby
files into the irb interpreter or at least point me in the right
direction on where to find documentation online for the irb
interpreter itself?

I appreciate everyone's help in advance.

Thanks & Regards,
--Nick

"Our characters are the result of our conduct." -- Aristotle


3 Answers

e

8/20/2006 2:21:00 PM

0

Nicholas Parsons wrote:
> Hello All!
>
> I'm new to Ruby and this group. I was hoping that someone could lend
> a helping hand involving the irb interpreter packaged with ruby
> version 1.8 on Mac OSX. I would like to import or load some classes
> that are defined in a separate .rb file on my hard disk into an
> interactive session of irb. I tried invoking the load() function
> with '~/classes.rb' as a parameter. The interpreter gave me a 'true'
> value in response. But when I tried to create an instance of one of
> the classes defined in the file I got a undefined class error from
> irb. I also tried using the require keyword with the same path in
> quotes to load that class file and it produced the same results.
>
> So, can anyone tell me how to import those class definition ruby
> files into the irb interpreter or at least point me in the right
> direction on where to find documentation online for the irb
> interpreter itself?
>
> I appreciate everyone's help in advance.

One thing to try is load '/home/myname/classes.rb' or,
alternatively, load File.expand_path('~/classes.rb').
Wildcards generally cause problems with filename
strings unless expanded.

Not sure why you are getting 'true' unless it is actually
finding the file--it could of course be that the file itself
is missing something or you are not accessing the namespace
or something.

> Thanks & Regards,
> --Nick


--
Posted via http://www.ruby-....

Logan Capaldo

8/20/2006 2:22:00 PM

0


On Aug 20, 2006, at 10:14 AM, Nicholas Parsons wrote:

> Hello All!
>
> I'm new to Ruby and this group. I was hoping that someone could
> lend a helping hand involving the irb interpreter packaged with
> ruby version 1.8 on Mac OSX. I would like to import or load some
> classes that are defined in a separate .rb file on my hard disk
> into an interactive session of irb. I tried invoking the load()
> function with '~/classes.rb' as a parameter. The interpreter gave
> me a 'true' value in response. But when I tried to create an
> instance of one of the classes defined in the file I got a
> undefined class error from irb. I also tried using the require
> keyword with the same path in quotes to load that class file and it
> produced the same results.
>

This should have worked. Can we see your code?

> So, can anyone tell me how to import those class definition ruby
> files into the irb interpreter or at least point me in the right
> direction on where to find documentation online for the irb
> interpreter itself?
>
> I appreciate everyone's help in advance.
>
> Thanks & Regards,
> --Nick
>
> "Our characters are the result of our conduct." -- Aristotle
>
>


Nicholas Parsons

8/20/2006 2:29:00 PM

0

Hi Eero,

The load File.expand_path('~/classes.rb) that you mentioned did the
trick.

Thanks again for your help!

--Nick

On Aug 20, 2006, at 10:21 AM, Eero Saynatkari wrote:

> Nicholas Parsons wrote:
>> Hello All!
>>
>> I'm new to Ruby and this group. I was hoping that someone could lend
>> a helping hand involving the irb interpreter packaged with ruby
>> version 1.8 on Mac OSX. I would like to import or load some classes
>> that are defined in a separate .rb file on my hard disk into an
>> interactive session of irb. I tried invoking the load() function
>> with '~/classes.rb' as a parameter. The interpreter gave me a 'true'
>> value in response. But when I tried to create an instance of one of
>> the classes defined in the file I got a undefined class error from
>> irb. I also tried using the require keyword with the same path in
>> quotes to load that class file and it produced the same results.
>>
>> So, can anyone tell me how to import those class definition ruby
>> files into the irb interpreter or at least point me in the right
>> direction on where to find documentation online for the irb
>> interpreter itself?
>>
>> I appreciate everyone's help in advance.
>
> One thing to try is load '/home/myname/classes.rb' or,
> alternatively, load File.expand_path('~/classes.rb').
> Wildcards generally cause problems with filename
> strings unless expanded.
>
> Not sure why you are getting 'true' unless it is actually
> finding the file--it could of course be that the file itself
> is missing something or you are not accessing the namespace
> or something.
>
>> Thanks & Regards,
>> --Nick
>
>
> --
> Posted via http://www.ruby-....
>