[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Unintentional hype of Ruby irb and ri

stephen.tashiro

3/30/2006 5:31:00 PM

Perhaps an inflamatory title - but it answers some simple questions.

Having looked at the Pixaxe book and visited various websites with Ruby
tutorials, I think there is an unintentional hype of certain Ruby
features. We may blame this on the distributors of software. For
example, the authors tell us how easy it is to use irb. On my Redhat
Enterprise Linux machine, ruby puts("Hello World") ran fine. But irb
was not a command known to bash. The redhat distribution has the
packages:
ruby-docs-1.8.1-7.EL4.2
ruby-tcltk-1.8.1-7.EL4.2
ruby-1.8.1-7.EL4.2
ruby-mode-1.8.1-7.EL4.2
ruby-devel-1.8.1-7.EL4.2
ruby-libs-1.8.1-7.EL4.2
irb-1.8.1-7.EL4.2
So you might get ruby but not irb.

The authors extol the virtues of ri. I found that ri File (or ri
almost anything) gave:
No ri documentation found in:
/usr/share/ri/1.8/system
/usr/share/ri/1.8/site
/root/.rdoc

These problems can be blamed on incompetent packaging or installation
of Ruby, but it seems to me that the authors of Ruby tutorials should
warn their readers about such problems and perhaps give some hints
about how to resolve them.

In Redhat Enterprise Linux 4, I was able to resolve the irb problem
simply by installing the irb-1.8.1-7 package.

At to the ri problem,I found no tutorials that mention rdoc or
configure ri. Reading the output of
ri -h
I concluded it would suffice to run
rdoc --ri
which creates a director called "doc" in my home directory. And this
makes ri work for the basic ruby objects. (Of course a more efficient
way on a mult-user system would be to create this "doc" file in only
one location and direct the ri for each user to it. It would be nice
to have a simple example of this. )

14 Answers

Ara.T.Howard

3/30/2006 5:59:00 PM

0

Hans Fugal

3/30/2006 6:27:00 PM

0


ara.t.howard@noaa.gov wrote:
> we use rhe on all our machines and i can tell you this: the rh ruby
> rpms are
> broken, broken, broken, broken - do not use them and please complain to
> redhat
> (i have several times).
>
> all the issues you are seeing are resolved by using almost any installation
> method besides rhe rpms. it even works on fedora.
>
> i manage about 50 machines and we've taken the compile route - however,
> since
> all the boxes see a common nfs mount we install only once there.
>
> rhe rpms are really really bad in general and should be avoided - for
> example
> the image magic packages break (silently) loseless compression of
> jp2s... the
> perl rpm has a userland kernel panic causing bug, etc, etc.
>
> we use plain vanilla rhe, installing anything 'important' via
> compilation and
> have 100% success with this approach. it's also immune to the
> auto-upgrade of
> enterprise systems breaking 24x7 systems on a late sunday evening.
>
> the reality is that there is exactly one method of installing ruby, or
> anything else for that matter, that will work on any platform:
>
> ./configure --prefix=dst && make && sudo make install
>
> this becomes __really__ important once one starts installing gems that
> auto-compile and then upgrade ruby using rpms - only to have all gems start
> giving bus errors... correct compilation avoids this entirely in
> addition to
> allowing multiple ruby versions to be installed (which we require).
>
> sad. but true.

I can second that. I have never worked with a more frustrating
distribution than R_HEL_ (emphasis added).

Randy Kramer

3/30/2006 10:09:00 PM

0

On Thursday 30 March 2006 12:59 pm, ara.t.howard@noaa.gov wrote:
> i manage about 50 machines and we've taken the compile route - however,
> since all the boxes see a common nfs mount we install only once there.

Hmm, interesting idea--tell me more:

* Is that partition mounted as one of the standard partitions (/usr...) or
something else?

* Do you have to do anything on each of those 50 machines, or just mount
the NFS partition--hmm, I guess you'd at least have to add something to the
PATH of each user (at least, if a non-standard partition)?

I might try this, or even on a local non-standard partition (I guess I just
have to set the prefix appropriately).

This might solve some problems for me--I'm trying to get TkHTML working for
me, and by now I'm concerned that I've tried so many things I've created more
problems for myself--I could start completely over on a new partition.

Then I guess I'd have to do the ./configure --prefix=dst && make && sudo make
install process for:

Ruby
tcltk (or ActiveTcl)
TkHTML (although in reading the instructions for this I realize there are some
special things to deal with, like the "parallel" bld directory)

More info:

Part of my problem is that I've compiled Ruby, then installed ActiveTcl, and I
don't know how to uninstall something that I installed by compiling.
ActiveTcl seemed to have an uninstall.tcl script, but that failed for me. I
guess I'll just go around and delete all files and directories that look like
they have anything to do with Ruby, tcltk, ActiveTcl, or TkHTML, and then
start over.

This is on a Mandriva2006 system. I don't know whether the rpms on Mandriva
are to blame in any way--I suspect most of the problem(s) are just my
ignorance/inexperience in setting something like this up.

Randy Kramer



Ara.T.Howard

3/30/2006 10:22:00 PM

0

stephen.tashiro

3/30/2006 11:30:00 PM

0

I tried the suggestion of installing from source and I like the result
better. (My suggestion to run rdoc --ri is only useful if you run it
in some directory whose tree contains the source code (*.c) files for
Ruby. ) After an install from source with
../configure
make
su
make install

The ri and irb commands work fine. But when I try to use FxRuby, the
extension for the Fox Gui Toolkit, there are problems. The extension
wants the library libruby.so, which is missing. I tried

make distclean
../configure --enable-shared --enable-install-doc --enable-pthread
(As if I really knew what I was doing !)
make
make install-all

Then I had a libruby.so and ruby, irb and ri still worked.

However the elementary test
irb> require 'fox14'
fails since it cannot find the files fox14/core.rb and fox14/core.so.
An strace of this process shows it is looking in the correct path for
the files. (I resorted to running irb in the fox14 directory.) The
problem is that the files were not produced when I compiled fox-1.4.32.

I'll be delighted if someone can tell me the answer to that problem.
However to return to generalities: I think people trying to use Ruby
face more of a challenge than Perl and Python users since they are less
likely to find Ruby installed and ready-to-go. In the current epoch,
writers of tutorials would do better to give detailed coverage of
installation problems. Otherwise the pages about how easy and nice
Ruby is will seem a fraud.

For example, if you read the typical exposition of the
require 'xyz'
"command, it doesn't explain how the name 'xyz' is connected to any
file on the machine. By experiment it seems to search for a directory
named 'xyz'. What paths does it take? What files does it need in that
directory? If everything is perfectly installed you don't have to
worry about this, but in practice you do.

Ryan Allen

3/30/2006 11:58:00 PM

0

Hi Guys (and Gals!)

This is my first post on the list, so Hello!

Something very strange is happening (as far as I can tell) with a
float comparison; here is the code in question:

("55.59".to_f / 100) == 0.5559 # returns false

However:

"55.59".to_f / 100 # returns Float 0.5559
0.5559 # returns Float 0.5559
0.5559 == 0.5559 # returns true

And more!:

("55.5".to_f / 100) == 0.555 # returns true
("55.53".to_f / 100) == 0.5553 # returns true
("55.56".to_f / 100) == 0.5556 # returns true
("55.58".to_f / 100) == 0.5558 # returns true
("55.59".to_f / 100) == 0.5559 # returns false !!
("44.59".to_f / 100) == 0.4449 # returns true !!
("44.59".to_f / 100) == 0.4449 # returns false !!!!

It doesn't seem to like .59's... What did .59 ever do?

I picked this up while writing a unit test, I've run this code in irb
and I'm not sure what's going on...

Can anyone shed some light on this?

I'm using ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]

Cheers,
Ryan.


Mike Stok

3/31/2006 12:05:00 AM

0


On 30-Mar-06, at 6:58 PM, Ryan Allen wrote:

> Hi Guys (and Gals!)
>
> This is my first post on the list, so Hello!
>
> Something very strange is happening (as far as I can tell) with a
> float comparison; here is the code in question:
>
> ("55.59".to_f / 100) == 0.5559 # returns false
>
> However:
>
> "55.59".to_f / 100 # returns Float 0.5559
> 0.5559 # returns Float 0.5559
> 0.5559 == 0.5559 # returns true
>
> And more!:
>
> ("55.5".to_f / 100) == 0.555 # returns true
> ("55.53".to_f / 100) == 0.5553 # returns true
> ("55.56".to_f / 100) == 0.5556 # returns true
> ("55.58".to_f / 100) == 0.5558 # returns true
> ("55.59".to_f / 100) == 0.5559 # returns false !!
> ("44.59".to_f / 100) == 0.4449 # returns true !!
> ("44.59".to_f / 100) == 0.4449 # returns false !!!!
>
> It doesn't seem to like .59's... What did .59 ever do?
>
> I picked this up while writing a unit test, I've run this code in
> irb and I'm not sure what's going on...
>
> Can anyone shed some light on this?
>
> I'm using ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]
>
> Cheers,
> Ryan.

You might want to look at http://docs.sun.com/source...
ncg_goldberg.html and http://support.microsoft.com/...

ratdog:~ mike$ irb
irb(main):001:0> '%.40f' % 0.5559
=> "0.5558999999999999497291014449729118496180"
irb(main):002:0> '%.40f' % (55.59 / 100)
=> "0.5559000000000000607514039074885658919811"
irb(main):003:0> '%.40f' % ("55.59".to_f / 100)
=> "0.5559000000000000607514039074885658919811"


Mike

--

Mike Stok <mike@stok.ca>
http://www.stok...

The "`Stok' disclaimers" apply.






matthew.moss.coder

3/31/2006 12:07:00 AM

0

> ("44.59".to_f / 100) == 0.4449 # returns true !!
> ("44.59".to_f / 100) == 0.4449 # returns false !!!!

Typos? You typed the same exact line twice and it comes back with two
different answers?

In any case, exact equality comparisons of floating-point numbers is
bad. Don't do it.

Either compare with a small threshold, or deal with rationals.


Ara.T.Howard

3/31/2006 12:13:00 AM

0

Tim Hunter

3/31/2006 12:14:00 AM

0

Ryan Allen wrote:
> Hi Guys (and Gals!)
>
> This is my first post on the list, so Hello!
>
> Something very strange is happening (as far as I can tell) with a float
> comparison; here is the code in question:
>
> ("55.59".to_f / 100) == 0.5559 # returns false
>
> However:
>
> "55.59".to_f / 100 # returns Float 0.5559
> 0.5559 # returns Float 0.5559
> 0.5559 == 0.5559 # returns true
>
> And more!:
>
> ("55.5".to_f / 100) == 0.555 # returns true
> ("55.53".to_f / 100) == 0.5553 # returns true
> ("55.56".to_f / 100) == 0.5556 # returns true
> ("55.58".to_f / 100) == 0.5558 # returns true
> ("55.59".to_f / 100) == 0.5559 # returns false !!
> ("44.59".to_f / 100) == 0.4449 # returns true !!
> ("44.59".to_f / 100) == 0.4449 # returns false !!!!
>
> It doesn't seem to like .59's... What did .59 ever do?
>
> I picked this up while writing a unit test, I've run this code in irb
> and I'm not sure what's going on...
>
> Can anyone shed some light on this?
>
> I'm using ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]
>
> Cheers,
> Ryan.
>
>

The comparison of floating-point numbers is notoriously problematic
throughout all computing, not just Ruby. Here's a good description of
the problem: http://en.wikipedia.org/wiki/Floa.... You can also
find many discussions of this same "problem" by searching the archives
of this list.

Typically you don't test two floating-point numbers for equality, you
test that the difference is very small. This is what the assert_in_delta
assertion is for.