Numeric#coerce docs are a disaster

===
num.coerce(numeric) → array

If aNumeric is the same type as num, returns an array containing
aNumeric and num. Otherwise, returns an array with both aNumeric and num
represented as Float objects. This coercion mechanism is used by Ruby to
handle mixed-type numeric operations: it is intended to find a
compatible common type between the two operands of the operator.

1.coerce(2.5) #=> [2.5, 1.0]
1.2.coerce(3) #=> [3.0, 1.2]
1.coerce(2) #=> [2, 1]

===

http://ruby-doc.org/core/classes/Numeric.html#M000959

aNumeric? No indication the method can take a block. Really, whoever
wrote that should be banned from ever writing anything in the docs
again.

You are free to improve the documentation and open a ticket on redmine
assigned to Eric H…

  1. I don’t know how coerce works.
  2. I don’t know how to open a ticket, and I don’t plan on learning.
    I’ve tried to go through official channels to add patches to docs in
    other languages, and it has always ended up wasting hours of my time.
  3. If I did know how coerce worked, I should be able to add my comments
    directly to the docs.
  4. The best I can do at this time is to point out the problems by
    posting in this forum, and hope that someone who knows what they are
    doing will able to do something about it.

On Tue, Aug 2, 2011 at 12:40 PM, 7stud – [email protected]
wrote:

  1. I don’t know how coerce works.

http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.html

Cheers

robert

Roughly speaking: if ‘a’ is a numeric type, and ruby doesn’t know how to
make

a.+(b)

work (where ‘+’ can be any binary math operator), then it calls
b.coerce(a) and repeats the operation on the returned pair of values.

1 + “2”
TypeError: String can’t be coerced into Fixnum
from (irb):1:in `+’
from (irb):1
from :0

class String; def coerce(other); [other, self.to_f]; end; end
=> nil

1 + “2”
=> 3.0

1 - “2”
=> -1.0

On Tue, Aug 2, 2011 at 11:40 AM, 7stud – [email protected]
wrote:

  1. I don’t know how coerce works.
  2. I don’t know how to open a ticket, and I don’t plan on learning.
    That’s too much of a hassle.
  3. If I did know how coerce worked, I should be able to add my comments
    directly to the docs.

I would think this information could have gone into the original email
you
sent with the complaints about the documentation. :slight_smile:

Since you’ve ruled out learning how to open a ticket (although I’m
curious
how you know it’s too much hassle when you don’t know what it involves),
for
the sake of anyone else wondering how it’s done, these might be of use:

http://blog.segment7.net/2011/05/09/ruby-1-9-3-documentation-challenge
http://blog.steveklabnik.com/2011/05/10/contributing-to-ruby-s-documentation.html

The Ruby issue tracker is at http://redmine.ruby-lang.org/ too.

If I did know how coerce worked, I should be able to add my comments
directly to the docs.

Can you elaborate on this? I actually care a lot about improving
Ruby’s docs, but I’m not sure what you mean here. What’s the UX of
this like?

On Aug 2, 2011, at 10:09 AM, Steve K. wrote:

If I did know how coerce worked, I should be able to add my comments
directly to the docs.

Can you elaborate on this? I actually care a lot about improving
Ruby’s docs, but I’m not sure what you mean here. What’s the UX of
this like?

This is supported on APIDock, which hosts docs for Ruby and Rails

http://apidock.com/

Not sure if this is what the OP is talking about but it is available, if
not official.

Jason

On Tue, Aug 02, 2011 at 07:40:55PM +0900, 7stud – wrote:

  1. I don’t know how coerce works.
  2. I don’t know how to open a ticket, and I don’t plan on learning.
    That’s too much of a hassle.

Contributing is “too much of a hassle”?

Hi,

On 02.08.2011 14:55, Robert K. wrote:

On Tue, Aug 2, 2011 at 12:40 PM, 7stud – [email protected] wrote:

  1. I don’t know how coerce works.

http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.html

When I read this and the response form Adam:

On 02.08.2011 12:32, Adam P. wrote:

You are free to improve the documentation and open a ticket on redmine
assigned to Eric H…

it reminds me what I just wrote a few weeks ago, no real feedback at
all: Ruby Readline - and why ruby can learn from python - Ruby - Ruby-Forum .

If it were me, I’d bow before Robert for doing this great work, ask for
his permission and simply stuff all his wisdom into the docs and let the
world joy on it.

My problem with that approach and this here

On 02.08.2011 13:26, Adam P. wrote:

http://blog.segment7.net/2011/05/09/ruby-1-9-3-documentation-challenge

http://blog.steveklabnik.com/2011/05/10/contributing-to-ruby-s-documentation.html

is the following: Roberts post includes a and much more widened example
and I’d be all for including it, but it doesn’t fit will with how rdocs
are most commonly used currently, that is, one page for all methods. If
documentation for methods becomes to long as I outlined, things get
noticeably unreadable.

I’ve no further solution, but somehow it strikes me that the whole ruby
documentation misses the next evolutionary step, away from the docs only
generated from the sources to a) possible include much more meta
documentation (manuals, tutorials, etc.) and b) provide a/the
official ruby docs, not just class based docs, but also including
introductory articles etc., e.g. from the existing ruby wikibook and so
on, allowing comments on the docs as others mentioned and what not
features.

But unfortunately it’s lacking a power behind, a group of volunteers a)
providing the technical environment and b) writers. When I look at other
projects, e.g. PHP, the doc team not only provides infrastructure and
assistance, they’re also permanently communicating with the core
developers to properly document new things for a release, properly
describe backward compatibility problems (I mean, just look at the list
at PHP: PHP Manual - Manual ).

I wish I’d the skills for either forming a basis or writing good docs,
unfortunately I’m quite un-gifted for the latter (I still try to improve
it and contribute) and I seriously lack ruby-foo or whatnot for the
former.

  • Markus

On Aug 2, 2011, at 7:30 AM, Markus F. wrote:

assigned to Eric H…

it reminds me what I just wrote a few weeks ago, no real feedback at
all: Ruby Readline - and why ruby can learn from python - Ruby - Ruby-Forum .

Since you posted it to ruby-talk and not to ruby-core (or a ticket) I
missed it. In brief, if you think it can be better, file a ticket.

The reason I say “file a ticket” is because I will forget if we only
talk about it here. I’m very busy with both work and preparing for the
Ruby 1.9.3 release so I probably won’t have free time available to work
on these things for a while now.

From your post:

Well, the problem as I see it is that tutorial-like examples, when you
have quite some of them, don’t really fit well within a discrete method
documentation. It makes it hard for the developer to discover. IMHO all
the examples from Readline.readline and what I’ve added should be moved
out either into the README or into the Readline module description and
the actual method documentations should be made more slim. But who to
make a call for anything here?

If you think the organization of something is poor then file a ticket
proposing a reorganization. I agree that it’s easier to read when some
examples are moved up to the top level.

Take a look at the documentation of Net::HTTP or OpenSSL in Ruby
1.9.3-preview1. They’ve been reorganized and improved to show you the
various ways you can use the two libraries in one place with slimmer
documentation on individual methods. I think this is a vast improvement
over hunting through the 10 or 15 methods you may need to call to get a
working program, and I think Readline would benefit from a similar
reorganization.

When I generate the docs from it, it looks like this
http://i.imgur.com/e7U5G.png . Ugh. The headings don’t suit well and the
source code has no highlighting (in case your wonder: that’s FF 5 with
150% full-page zoom).

If you think the RDoc HTML output can be better then file a ticket or
write a new template or generator. The current default generator,
Darfkish, was contributed by Michael G… HTML and web browsers
have advanced quite a bit since it was included so if something nicer is
built it can be added to RDoc and be made the default.

If it were me, I’d bow before Robert for doing this great work, ask for
his permission and simply stuff all his wisdom into the docs and let the
world joy on it.

Done!

noticeably unreadable.

I’ve no further solution, but somehow it strikes me that the whole ruby
documentation misses the next evolutionary step, away from the docs only
generated from the sources to a) possible include much more meta
documentation (manuals, tutorials, etc.) and b) provide a/the
official ruby docs, not just class based docs, but also including
introductory articles etc., e.g. from the existing ruby wikibook and so
on, allowing comments on the docs as others mentioned and what not features.

Ruby still needs more of two types of documentation, the manuals,
tutorials, etc. and the class and method-level documentation of the
standard library. Through the efforts of my documentation challenge the
latter has grown to having ⅔ of the standard library documented for Ruby
1.9.3 out of about 15,000 items. I don’t know of anybody addressing the
former beyond these recent discussion and what’s present at
ruby-doc.org.

But unfortunately it’s lacking a power behind, a group of volunteers a)
providing the technical environment and b) writers. When I look at other
projects, e.g. PHP, the doc team not only provides infrastructure and
assistance, they’re also permanently communicating with the core
developers to properly document new things for a release, properly
describe backward compatibility problems (I mean, just look at the list
at PHP: PHP Manual - Manual ).

I became a Ruby committer through submitting documentation patches, and
anyone can become a committer the same way. I did a decent job of
committing documentation patches in a timely manner, but it would be
great if I could have some extra help. I don’t see any reason why
people couldn’t be both.

I wish I’d the skills for either forming a basis or writing good docs,
unfortunately I’m quite un-gifted for the latter (I still try to improve
it and contribute) and I seriously lack ruby-foo or whatnot for the former.

For the documentation challenge, writing good documentation was
most-preferred, but I applied even “poor” documentation patches after
appropriate editing or expansion. For every patch I wasn’t able to
directly apply I provided feedback to the submitter. In total, I think
only two patches weren’t applied out of between 40 and 50, one that
duplicated an earlier submission and one being a mistaken typo fix about
the math meaning of a number range like “[0, 1)”.

For class and method-level documentation even poor documentation can be
edited or expanded into something good! Through feedback even you can
write good documentation! Please do not be afraid of rejection, I try
very hard to avoid rejecting documentation patches.

On Aug 2, 2011, at 08:39 , Darryl L. Pierce wrote:

On Tue, Aug 02, 2011 at 07:40:55PM +0900, 7stud – wrote:

  1. I don’t know how to open a ticket, and I don’t plan on learning.
    That’s too much of a hassle.

Contributing is “too much of a hassle”?

For an ass like 7stud: yes.

For the rest of us: no.

On Tue, Aug 2, 2011 at 9:20 PM, Eric H. [email protected] wrote:

On Aug 2, 2011, at 5:55 AM, Robert K. wrote:

On Tue, Aug 2, 2011 at 12:40 PM, 7stud – [email protected] wrote:

  1. I don’t know how coerce works.

http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.html

May I use this as source material for better documentation of Numeric and
Numeric#coerce in Ruby? I don’t think I’ll be able to include all of it, but there
are certainly sections I may use verbatim.

Hi Eric,

I’m happy if I can help Ruby and the community with this. Please go
ahead and use those parts that you think are useful. For the
remainder you can always include a link for the full story if that
should be necessary.

Btw, I just notice that one reason for the lack of good docs for this
feature might be the fact that there is no single class where this
naturally fits in. All numeric classes have #coerce and all numeric
operators in all those classes use it.

Kind regards

robert

On 02.08.2011 22:40, Robert K. wrote:

Btw, I just notice that one reason for the lack of good docs for this
feature might be the fact that there is no single class where this
naturally fits in. All numeric classes have #coerce and all numeric
operators in all those classes use it.

In python terms [*] I’d say it would fit into

well; a good example why only API docs are not sufficient for such an
undertaking.

[*] I say this because most people seem to refer to Python as a better
existing documentation model for the time being

sincerely