Forum: Ruby Strange ruby documentation ?!

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.
93697354fea1f7bae30d3ab89917c4c3?d=identicon&s=25 Alin Popa (alin_popa)
on 2008-12-10 16:04
Hi,

I noticed soon something weird about Object documentation (in fact, one
of my colleagues saw it and he asked me what's the catch):

- Object class (http://www.ruby-doc.org/core/classes/Object.html) have
one method called to_yaml. Now, the funny thing is that when trying to
do that:

irb(main):001:0> a = "abc"
=> "abc"
irb(main):002:0> a.to_yaml
NoMethodError: undefined method `to_yaml' for "abc":String
  from (irb):2
  from :0

but after require 'yaml' everything is ok.

Ok, I know that yaml is placing this method to Object class when
required, but why is it by default documented in Object class ? What may
be the reason ?

Thanks.
Ff9e18f0699bf079f1fc91c8d4506438?d=identicon&s=25 James Britt (Guest)
on 2008-12-10 18:32
(Received via mailing list)
Alin Popa wrote:
>
> Ok, I know that yaml is placing this method to Object class when
> required, but why is it by default documented in Object class ? What may
> be the reason ?
>

It's the way rdoc currently works; it parses a set of files and rolls up
methods found for the various classes and modules it encounters.  It is
not able to indicate from where a method originated or that certain
methods are provided on an object only when one or another module is
included.


--
James Britt

www.happycamperstudios.com   - Wicked Cool Coding
www.jamesbritt.com           - Playing with Better Toys
www.ruby-doc.org             - Ruby Help & Documentation
www.rubystuff.com            - The Ruby Store for Ruby Stuff
93697354fea1f7bae30d3ab89917c4c3?d=identicon&s=25 Alin Popa (alin_popa)
on 2008-12-10 18:42
James Britt wrote:
> Alin Popa wrote:
>>
>> Ok, I know that yaml is placing this method to Object class when
>> required, but why is it by default documented in Object class ? What may
>> be the reason ?
>>
>
> It's the way rdoc currently works; it parses a set of files and rolls up
> methods found for the various classes and modules it encounters.  It is
> not able to indicate from where a method originated or that certain
> methods are provided on an object only when one or another module is
> included.
>
>
> --
> James Britt
>
> www.happycamperstudios.com   - Wicked Cool Coding
> www.jamesbritt.com           - Playing with Better Toys
> www.ruby-doc.org             - Ruby Help & Documentation
> www.rubystuff.com            - The Ruby Store for Ruby Stuff

Thanks James,

It makes sense.
This topic is locked and can not be replied to.