Nubish 2 - Of require and Ruby CVS

R

Ross Bamford

Hi again folks,

Thanks for the excellent answers yesterday :) I've been busy again today,
and now of course I have some more questions. Only a couple, so here goes:

1) I wanted to use Rake's file commands in IRB, but was stuck because I
didn't want the file ops on every object. I guess(?) this is executed by
rake when it's loaded, but by experimenting a bit I found out something
very interesting - if I do the following:

def init_sh
@sh = Object.new
class << @sh
require 'rake' # <= it works!!

# rake doesn't do 'ls' with opts
def ls(*o) `ls #{o.join(' ')}`.split("\n") end
end
end

then the file op methods get applied to @sh only. Now, I honestly didn't
expect that to work, and I have to say it frightens me a bit. I don't
know, for example, what happens with objects instantiated in that 'scope'
(or is this about namespaces?) if they get passed back to the main
program? I'd guess the methods are retained, because that's what happens
with the sh object, right? (I can call the file ops from IRB), but I've
fallen into that trap before ;) If that's so, then what happens in case of
a conflict? How does it work, and are there (m)any gotchas to watch for?

2) Also, if I change the require for include Rake (no require 'rake'
anywhere), then the methods seem to get applied across all Objects, as
before. I cannot understand why, esp. given 1) above.

3) I checked out Ruby CVS (HEAD) to get a look at what might be changing.
I get the feeling this is an obvious question, but make says:

[ ... ]
gcc -g -O2 -DRUBY_EXPORT -I. -I. -c ruby.c
gcc -g -O2 -DRUBY_EXPORT -I. -I. -c signal.c
gcc -g -O2 -DRUBY_EXPORT -I. -I. -c sjis.c
make: *** No rule to make target `vsnprintf.c', needed by `sprintf.o'.
Stop.

I searched around a bit and found a few references, including some to
moved libraries and many other programs, but not a great deal related to
Ruby. Has anyone seen and maybe got past this? I'm on Fedora Core 4,
Kernel 2.6.13-1.1526_FC4, gcc (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5).

Thanks again in advance,
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top