[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

require and the site_ruby directory...

Just Another Victim of the Ambient Morality

8/18/2006 2:31:00 AM

I placed a Ruby script in the site_ruby directory, expecting to find it
from other ruby scripts using the "require" keyword but, to my surprise, it
does nothing.
Do I have no idea how "require" works? How does "require" find files to
load?
Thank you...


lib/ruby/site_ruby/1.8/file_I_want_to_load.rb



9 Answers

Just Another Victim of the Ambient Morality

8/18/2006 2:59:00 AM

0


"Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
in message news:9D9Fg.541757$C62.90805@fe12.news.easynews.com...
> I placed a Ruby script in the site_ruby directory, expecting to find it
> from other ruby scripts using the "require" keyword but, to my surprise,
> it does nothing.
> Do I have no idea how "require" works? How does "require" find files
> to load?
> Thank you...

Okay, it's failling specifically for mechanize. If I make another ruby
script, that works properly. So, what's with mechanize?
Thank you...



Just Another Victim of the Ambient Morality

8/18/2006 3:19:00 AM

0


"Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
in message news:k2aFg.542068$C62.362943@fe12.news.easynews.com...
>
> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
> in message news:9D9Fg.541757$C62.90805@fe12.news.easynews.com...
>> I placed a Ruby script in the site_ruby directory, expecting to find
>> it from other ruby scripts using the "require" keyword but, to my
>> surprise, it does nothing.
>> Do I have no idea how "require" works? How does "require" find files
>> to load?
>> Thank you...
>
> Okay, it's failling specifically for mechanize. If I make another ruby
> script, that works properly. So, what's with mechanize?
> Thank you...

...and "require 'rubygems'" doesn't help...
Thanks...



Just Another Victim of the Ambient Morality

8/18/2006 3:25:00 AM

0


"Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
in message news:xkaFg.542364$C62.447443@fe12.news.easynews.com...
>
> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
> in message news:k2aFg.542068$C62.362943@fe12.news.easynews.com...
>>
>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>> wrote in message news:9D9Fg.541757$C62.90805@fe12.news.easynews.com...
>>> I placed a Ruby script in the site_ruby directory, expecting to find
>>> it from other ruby scripts using the "require" keyword but, to my
>>> surprise, it does nothing.
>>> Do I have no idea how "require" works? How does "require" find files
>>> to load?
>>> Thank you...
>>
>> Okay, it's failling specifically for mechanize. If I make another
>> ruby script, that works properly. So, what's with mechanize?
>> Thank you...
>
> ...and "require 'rubygems'" doesn't help...
> Thanks...

...and I'm using Ruby 1.8.4...
Thanks...



Just Another Victim of the Ambient Morality

8/18/2006 3:47:00 AM

0


"Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
in message news:XpaFg.542444$C62.257947@fe12.news.easynews.com...
>
> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
> in message news:xkaFg.542364$C62.447443@fe12.news.easynews.com...
>>
>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>> wrote in message news:k2aFg.542068$C62.362943@fe12.news.easynews.com...
>>>
>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>> wrote in message news:9D9Fg.541757$C62.90805@fe12.news.easynews.com...
>>>> I placed a Ruby script in the site_ruby directory, expecting to find
>>>> it from other ruby scripts using the "require" keyword but, to my
>>>> surprise, it does nothing.
>>>> Do I have no idea how "require" works? How does "require" find
>>>> files to load?
>>>> Thank you...
>>>
>>> Okay, it's failling specifically for mechanize. If I make another
>>> ruby script, that works properly. So, what's with mechanize?
>>> Thank you...
>>
>> ...and "require 'rubygems'" doesn't help...
>> Thanks...
>
> ...and I'm using Ruby 1.8.4...
> Thanks...

Okay, so if I go into mechanize.rb and make this change to a line of
code:


# This is the original line of code...
#require 'web/htmltools/xmltree' # narf

# This is my hack to get the file to parse
require 'xmltree'


...and go into mechanize\parsing.rb and comment out this block of code:


# Aliasing functions to get rid of warnings. Remove when support for 1.8.2
# is dropped.
if RUBY_VERSION > "1.8.2"
alias :old_each_recursive :each_recursive
alias :old_find_first_recursive :find_first_recursive
alias :old_index_in_parent :index_in_parent
end


...it all parses. Otherwise, I get an undefined method error for
'each_recursive.' What's up with that? Do I have any reasonable
expectation of this working, now? Why the hell did I have to do all this?
Why can't this "just work?"
Thank you...




Just Another Victim of the Ambient Morality

8/18/2006 5:31:00 AM

0


"Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
in message news:NKaFg.144673$Em2.92508@fe10.news.easynews.com...
>
> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
> in message news:XpaFg.542444$C62.257947@fe12.news.easynews.com...
>>
>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>> wrote in message news:xkaFg.542364$C62.447443@fe12.news.easynews.com...
>>>
>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>> wrote in message news:k2aFg.542068$C62.362943@fe12.news.easynews.com...
>>>>
>>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>>> wrote in message news:9D9Fg.541757$C62.90805@fe12.news.easynews.com...
>>>>> I placed a Ruby script in the site_ruby directory, expecting to
>>>>> find it from other ruby scripts using the "require" keyword but, to my
>>>>> surprise, it does nothing.
>>>>> Do I have no idea how "require" works? How does "require" find
>>>>> files to load?
>>>>> Thank you...
>>>>
>>>> Okay, it's failling specifically for mechanize. If I make another
>>>> ruby script, that works properly. So, what's with mechanize?
>>>> Thank you...
>>>
>>> ...and "require 'rubygems'" doesn't help...
>>> Thanks...
>>
>> ...and I'm using Ruby 1.8.4...
>> Thanks...
>
> Okay, so if I go into mechanize.rb and make this change to a line of
> code:
>
>
> # This is the original line of code...
> #require 'web/htmltools/xmltree' # narf
>
> # This is my hack to get the file to parse
> require 'xmltree'
>
>
> ...and go into mechanize\parsing.rb and comment out this block of code:
>
>
> # Aliasing functions to get rid of warnings. Remove when support for
> 1.8.2
> # is dropped.
> if RUBY_VERSION > "1.8.2"
> alias :old_each_recursive :each_recursive
> alias :old_find_first_recursive :find_first_recursive
> alias :old_index_in_parent :index_in_parent
> end
>
>
> ...it all parses. Otherwise, I get an undefined method error for
> 'each_recursive.' What's up with that? Do I have any reasonable
> expectation of this working, now? Why the hell did I have to do all this?
> Why can't this "just work?"
> Thank you...

Okay, after _way_ too many code modifications, I got it to almost
work...
One way that it is defective is that it can't always parse the links of
a page. The strange thing is that it works find for some pages (like
slashdot.org) but completely fails for others (like rubyforge.org). When it
fails, it does so by failing to collect the URL of the link and the script
dies by sending a message to a nil object. I looked at the source and the
two pages seem to be the same to me. Can anyone guess what's going on?
Also, why didn't "mechanize" "just work?"
Thank you...



Justin Collins

8/18/2006 6:00:00 AM

0

Just Another Victim of the Ambient Morality wrote:
> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
> in message news:NKaFg.144673$Em2.92508@fe10.news.easynews.com...
>
>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote
>> in message news:XpaFg.542444$C62.257947@fe12.news.easynews.com...
>>
>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>> wrote in message news:xkaFg.542364$C62.447443@fe12.news.easynews.com...
>>>
>>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>>> wrote in message news:k2aFg.542068$C62.362943@fe12.news.easynews.com...
>>>>
>>>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>>>> wrote in message news:9D9Fg.541757$C62.90805@fe12.news.easynews.com...
>>>>>
>>>>>
<snip a bunch>
> Okay, after _way_ too many code modifications, I got it to almost
> work...
> One way that it is defective is that it can't always parse the links of
> a page. The strange thing is that it works find for some pages (like
> slashdot.org) but completely fails for others (like rubyforge.org). When it
> fails, it does so by failing to collect the URL of the link and the script
> dies by sending a message to a nil object. I looked at the source and the
> two pages seem to be the same to me. Can anyone guess what's going on?
> Also, why didn't "mechanize" "just work?"
> Thank you..

It sounds like you didn't install this in any normal fashion? I have yet
to run into public Ruby libraries which require you to copy them into
the Ruby directory. Plus, I know Mechanize is available as a gem.
Why are you copying it manually? I would suspect this as the root of the
issue, although it's hard to tell.

-Justin

Just Another Victim of the Ambient Morality

8/18/2006 6:29:00 AM

0


"Justin Collins" <collinsj@seattleu.edu> wrote in message
news:44E55BF8.3040208@seattleu.edu...
> Just Another Victim of the Ambient Morality wrote:
>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>> wrote in message news:NKaFg.144673$Em2.92508@fe10.news.easynews.com...
>>
>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>> wrote in message news:XpaFg.542444$C62.257947@fe12.news.easynews.com...
>>>
>>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>>> wrote in message news:xkaFg.542364$C62.447443@fe12.news.easynews.com...
>>>>
>>>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>>>> wrote in message
>>>>> news:k2aFg.542068$C62.362943@fe12.news.easynews.com...
>>>>>
>>>>>> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com>
>>>>>> wrote in message
>>>>>> news:9D9Fg.541757$C62.90805@fe12.news.easynews.com...
>>>>>>
> <snip a bunch>
>> Okay, after _way_ too many code modifications, I got it to almost
>> work...
>> One way that it is defective is that it can't always parse the links
>> of a page. The strange thing is that it works find for some pages (like
>> slashdot.org) but completely fails for others (like rubyforge.org). When
>> it fails, it does so by failing to collect the URL of the link and the
>> script dies by sending a message to a nil object. I looked at the source
>> and the two pages seem to be the same to me. Can anyone guess what's
>> going on?
>> Also, why didn't "mechanize" "just work?"
>> Thank you..
>
> It sounds like you didn't install this in any normal fashion? I have yet
> to run into public Ruby libraries which require you to copy them into the
> Ruby directory. Plus, I know Mechanize is available as a gem.
> Why are you copying it manually? I would suspect this as the root of the
> issue, although it's hard to tell.

I appreciate that it's hard to tell.
I don't really know what gems are and I generally try to avoid things I
don't understand.
If you go to the sourceforge download site:

http://rubyforge.org/frs/?group_id=1453&relea...

You'll see that it comes in a .zip file with all the files in it. Now,
pehaps this opinion is naive of me but if the package doesn't simply work as
it is packaged, then it is horribly broken. I mean, really, what does the
gem do that's so different and what necessitates this difference?



Hal E. Fulton

8/18/2006 6:40:00 AM

0

Just Another Victim of the Ambient Morality wrote:
>
> I appreciate that it's hard to tell.
> I don't really know what gems are and I generally try to avoid things I
> don't understand.
> If you go to the sourceforge download site:
>
> http://rubyforge.org/frs/?group_id=1453&relea...
>
> You'll see that it comes in a .zip file with all the files in it. Now,
> pehaps this opinion is naive of me but if the package doesn't simply work as
> it is packaged, then it is horribly broken. I mean, really, what does the
> gem do that's so different and what necessitates this difference?

It may be broken.

What was in the zip file? Was there a setup.rb and if so, did you
run it?

There may be some config involved other than just copying files over.
That's usually the case, esp. if there are many files in the package.

Gems are smart enough to know what's necessary to install themselves
(e.g. invoke setup.rb properly). And installing a gem is usually as
easy as: gem install foobar (assuming you've got permissions, etc.)

Gems are there to make things easier, not harder. Usually they
succeed.


Hal

Just Another Victim of the Ambient Morality

8/18/2006 7:36:00 AM

0


"Hal Fulton" <hal9000@hypermetrics.com> wrote in message
news:44E560C0.5040501@hypermetrics.com...
> Just Another Victim of the Ambient Morality wrote:
>>
>> I appreciate that it's hard to tell.
>> I don't really know what gems are and I generally try to avoid things
>> I don't understand.
>> If you go to the sourceforge download site:
>>
>> http://rubyforge.org/frs/?group_id=1453&relea...
>>
>> You'll see that it comes in a .zip file with all the files in it.
>> Now, pehaps this opinion is naive of me but if the package doesn't simply
>> work as it is packaged, then it is horribly broken. I mean, really, what
>> does the gem do that's so different and what necessitates this
>> difference?
>
> It may be broken.
>
> What was in the zip file? Was there a setup.rb and if so, did you
> run it?

Well, if you follow the link, you can see for yourself!
There was no setup.rb or anything, although I've seen that before.
There was basically just two directories. One had mechanize and all it
needed (except for htmltools, which I had to go get, myself) and the other
hosted a rather large test application. At least, I assume it was a test
program since it was in a directory called "test."