Forum: Ruby Are the docs correct for spaceship <=> in String?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2009fd74d4eebb8b7805eb11dc88170b?d=identicon&s=25 unknown (Guest)
on 2008-12-04 22:27
(Received via mailing list)
Hello all,

First-time poster.. I apologize if I am posting to the wrong group.

I am teaching a class of high-schoolers in programming, using Ruby. I
gave them an exercise called "Stupid String Tricks" which was about
getting them comfortable using the online documentation for Ruby. The
assignment was to do five silly things with Strings and share their
results with the class.

While walking through the docs online during class, we decided to dig
into <=> and demonstrate how it works and how to interpret the docs.
We used this page:

http://www.ruby-doc.org/core/classes/String.html#M000778

I thought that page was the authoritative one.

I believe the operator/method behaves correctly, but believe the doc
is not correct.

<quote>

  str <=> other_str => -1, 0, +1

Comparison—Returns -1 if other_str is less than, 0 if other_str is
equal to, and +1 if other_str is greater than str.

</quote>

Isn't it the other way around? Shouldn't the return be -1 if str is
less than other_str? The class behavior and the examples in the docs
all behave that way.

If this is not the right place to get visibility for this, what is?

Thanks in advance.
54185df1d348bbd34587fcd4f8e4779b?d=identicon&s=25 Louis-Philippe (Guest)
on 2008-12-04 22:45
(Received via mailing list)
whats funny, is that the text of the documentation is wrong while the
examples are showing the right behaviour.
I'm sure somebody on this list as autoritative power on this doc!

2008/12/4 <thomas.c.mitchell@gmail.com>
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2008-12-05 22:28
(Received via mailing list)
On Thu, Dec 4, 2008 at 4:38 PM, Louis-Philippe <default@spiralix.org>
wrote:
> whats funny, is that the text of the documentation is wrong while the
> examples are showing the right behaviour.
> I'm sure somebody on this list as autoritative power on this doc!

You can subscribe and post to ruby-core, and/or file a ticket in Ruby's
tracker:
http://redmine.ruby-lang.org/

-greg
2009fd74d4eebb8b7805eb11dc88170b?d=identicon&s=25 Tom Mitchell (Guest)
on 2008-12-06 00:25
(Received via mailing list)
On Dec 5, 4:21 pm, Gregory Brown <gregory.t.br...@gmail.com> wrote:
> Technical Blaag at:http://blog.majesticseacreature.com
>  Non-tech stuff at:http://metametta.blogspot.com
> "Ruby Best Practices"  Book now in O'Reilly Roughcuts:http://rubybestpractices.com

Thanks. I just filed a bug.
355dfec2a7633db603db2a178bddb631?d=identicon&s=25 Eustáquio Rangel (Guest)
on 2008-12-06 00:51
(Received via mailing list)
>> > whats funny, is that the text of the documentation is wrong while the
>> > examples are showing the right behaviour.

Ouch. Glad to know that the behaviour is right, only the docs are
wrong. I was wondering if some code I made with that was running ok.
:-)
This topic is locked and can not be replied to.