irb newbie question

N

Nicholas Parsons

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
 
E

Eero Saynatkari

Nicholas said:
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.
 
L

Logan Capaldo

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

Nicholas Parsons

Hi Eero,

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

Thanks again for your help!

--Nick
 

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

irb problem 1
Driving irb from IO.popen 5
irb: require returns false? 1
irb question 8
How to use gems in irb on ubuntu? 3
Weirdest IRB / Rails console problem 3
irb question 5
irb in cygwin 1

Members online

Forum statistics

Threads
474,184
Messages
2,570,973
Members
47,530
Latest member
jameswilliam1

Latest Threads

Top