Why is the Enumerable module documented as included into the integer class

When I look at this page: Class: Integer (Ruby 3.1.1)
I see that the Enumerable module is included into the integer class.
But integer has no method that matches with the methods defined by the Enumerable class Module: Enumerable (Ruby 3.1.1)

So what does it mean to be an Included Module from the docs?

From Ruby's source, it doesn't seem to mention Integer as one of the classes that has Enumerable: ruby/enum.c at master · ruby/ruby · GitHub
Could this be a typo?

The point of a module is to provide methods to a class that includes it (mixes it in, in Ruby parlance). The whole point of that is the receiving class doesn't need to define those methods again. So if you call an enumerable method on an integer, it will still work there, even though there's no method defined in the actual class itself. In IRB, try calling `1.next`. What do you get?

Walter

···

On Mar 28, 2022, at 9:00 AM, Francois Buys <buys.fran@gmail.com> wrote:

When I look at this page: Class: Integer (Ruby 3.1.1)
I see that the Enumerable module is included into the integer class.
But integer has no method that matches with the methods defined by the Enumerable class Module: Enumerable (Ruby 3.1.1)

So what does it mean to be an Included Module from the docs?

From Ruby's source, it doesn't seem to mention Integer as one of the classes that has Enumerable: https://github.com/ruby/ruby/blob/master/enum.c#L4788-L4807
Could this be a typo?

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Actually, that's a bad example, as Integer doesn't include Enumerable, and it defines its own `next` method. But my point stands. Find an object that already includes Enumerable (like Array or Set or Hash) and you will find that it doesn't need to define an Enumerable method in order to use it.

Walter

···

On Mar 28, 2022, at 9:24 AM, Walter Lee Davis <waltd@wdstudio.com> wrote:

The point of a module is to provide methods to a class that includes it (mixes it in, in Ruby parlance). The whole point of that is the receiving class doesn't need to define those methods again. So if you call an enumerable method on an integer, it will still work there, even though there's no method defined in the actual class itself. In IRB, try calling `1.next`. What do you get?

Walter

On Mar 28, 2022, at 9:00 AM, Francois Buys <buys.fran@gmail.com> wrote:

When I look at this page: Class: Integer (Ruby 3.1.1)
I see that the Enumerable module is included into the integer class.
But integer has no method that matches with the methods defined by the Enumerable class Module: Enumerable (Ruby 3.1.1)

So what does it mean to be an Included Module from the docs?

From Ruby's source, it doesn't seem to mention Integer as one of the classes that has Enumerable: https://github.com/ruby/ruby/blob/master/enum.c#L4788-L4807
Could this be a typo?

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

The documentation seems wrong. As Integer doesn't include Enumerable and
the documentation says it includes.

···

On Mon, Mar 28, 2022 at 10:30 AM Walter Lee Davis <waltd@wdstudio.com> wrote:

Actually, that's a bad example, as Integer doesn't include Enumerable, and
it defines its own `next` method. But my point stands. Find an object that
already includes Enumerable (like Array or Set or Hash) and you will find
that it doesn't need to define an Enumerable method in order to use it.

Walter

> On Mar 28, 2022, at 9:24 AM, Walter Lee Davis <waltd@wdstudio.com> > wrote:
>
> The point of a module is to provide methods to a class that includes it
(mixes it in, in Ruby parlance). The whole point of that is the receiving
class doesn't need to define those methods again. So if you call an
enumerable method on an integer, it will still work there, even though
there's no method defined in the actual class itself. In IRB, try calling
`1.next`. What do you get?
>
> Walter
>
>> On Mar 28, 2022, at 9:00 AM, Francois Buys <buys.fran@gmail.com> wrote:
>>
>> When I look at this page: Class: Integer (Ruby 3.1.1)
>> I see that the Enumerable module is included into the integer class.
>> But integer has no method that matches with the methods defined by the
Enumerable class Module: Enumerable (Ruby 3.1.1)
>>
>> So what does it mean to be an Included Module from the docs?
>>
>> From Ruby's source, it doesn't seem to mention Integer as one of the
classes that has Enumerable:
https://github.com/ruby/ruby/blob/master/enum.c#L4788-L4807
>> Could this be a typo?
>>
>> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
>> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;
>
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

Ricardo Franco Andrade

*Software Engineer*

email: ricardo.krieg@gmail.com
skype: ricardo.krieg
phone: +55 (86) 9569 8521
linkedin: http://br.linkedin.com/in/ricardokrieg/
github: ricardokrieg (Ricardo Andrade) · GitHub

Can you link to the documentation where it's wrong? Integer clearly doesn't include Enumerable, it includes Comparable.

···

On 3/28/22 15:35, Ricardo Franco wrote:

The documentation seems wrong. As Integer doesn't include Enumerable and the documentation says it includes.

···

On Mon, Mar 28, 2022 at 10:38 AM hmdne <hmdne@airmail.cc> wrote:

Can you link to the documentation where it's wrong? Integer clearly
doesn't include Enumerable, it includes Comparable.

On 3/28/22 15:35, Ricardo Franco wrote:
> The documentation seems wrong. As Integer doesn't include Enumerable
> and the documentation says it includes.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

Ricardo Franco Andrade

*Software Engineer*

email: ricardo.krieg@gmail.com
skype: ricardo.krieg
phone: +55 (86) 9569 8521
linkedin: http://br.linkedin.com/in/ricardokrieg/
github: ricardokrieg (Ricardo Andrade) · GitHub

Interesting. Not in 3.0, but if the docs say it is in 3.1, I guess I'll have to install 3.1 and see...

3.0.3 :001 > Integer.included_modules
=> [Comparable, PP::ObjectMixin, Kernel]
3.0.3 :002 >

Walter

···

On Mar 28, 2022, at 9:43 AM, Ricardo Franco <ricardo.krieg@gmail.com> wrote:

Class: Integer (Ruby 3.1.1)

On Mon, Mar 28, 2022 at 10:38 AM hmdne <hmdne@airmail.cc> wrote:
Can you link to the documentation where it's wrong? Integer clearly
doesn't include Enumerable, it includes Comparable.

On 3/28/22 15:35, Ricardo Franco wrote:
> The documentation seems wrong. As Integer doesn't include Enumerable
> and the documentation says it includes.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

Ricardo Franco Andrade

Software Engineer

email: ricardo.krieg@gmail.com
skype: ricardo.krieg
phone: +55 (86) 9569 8521
linkedin: http://br.linkedin.com/in/ricardokrieg/
github: https://github.com/ricardokrieg

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

I see it on this page: Class: Integer (Ruby 3.1.1)

···

On 28 Mar 2022, at 15:48, Walter Lee Davis <waltd@wdstudio.com> wrote:

Interesting. Not in 3.0, but if the docs say it is in 3.1, I guess I'll have to install 3.1 and see...

3.0.3 :001 > Integer.included_modules
=> [Comparable, PP::ObjectMixin, Kernel]
3.0.3 :002 >

Walter

On Mar 28, 2022, at 9:43 AM, Ricardo Franco <ricardo.krieg@gmail.com> wrote:

Class: Integer (Ruby 3.1.1)

On Mon, Mar 28, 2022 at 10:38 AM hmdne <hmdne@airmail.cc> wrote:
Can you link to the documentation where it's wrong? Integer clearly
doesn't include Enumerable, it includes Comparable.

On 3/28/22 15:35, Ricardo Franco wrote:

The documentation seems wrong. As Integer doesn't include Enumerable
and the documentation says it includes.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

Ricardo Franco Andrade

Software Engineer

email: ricardo.krieg@gmail.com
skype: ricardo.krieg
phone: +55 (86) 9569 8521
linkedin: http://br.linkedin.com/in/ricardokrieg/
github: ricardokrieg (Ricardo Andrade) · GitHub

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

And that seems to be wrong. If I look in 3.1.1, and ask Ruby:

=> ruby-3.1.1 [ arm64 ]

# => - current
# =* - current && default
# * - default

waltd@Max ~ % irb
:001 > Integer.included_modules
=> [Comparable, PP::ObjectMixin, Kernel]
:002 >
                 
I do not see Enumerable in there...

Looks like a documentation fail to me...

Walter

···

On Mar 28, 2022, at 9:49 AM, Francois Buys <buys.fran@gmail.com> wrote:

I see it on this page: Class: Integer (Ruby 3.1.1)

On 28 Mar 2022, at 15:48, Walter Lee Davis <waltd@wdstudio.com> wrote:

Interesting. Not in 3.0, but if the docs say it is in 3.1, I guess I'll have to install 3.1 and see...

3.0.3 :001 > Integer.included_modules
=> [Comparable, PP::ObjectMixin, Kernel]
3.0.3 :002 >

Walter

On Mar 28, 2022, at 9:43 AM, Ricardo Franco <ricardo.krieg@gmail.com> wrote:

Class: Integer (Ruby 3.1.1)

On Mon, Mar 28, 2022 at 10:38 AM hmdne <hmdne@airmail.cc> wrote:
Can you link to the documentation where it's wrong? Integer clearly
doesn't include Enumerable, it includes Comparable.

On 3/28/22 15:35, Ricardo Franco wrote:

The documentation seems wrong. As Integer doesn't include Enumerable
and the documentation says it includes.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

Ricardo Franco Andrade

Software Engineer

email: ricardo.krieg@gmail.com
skype: ricardo.krieg
phone: +55 (86) 9569 8521
linkedin: http://br.linkedin.com/in/ricardokrieg/
github: ricardokrieg (Ricardo Andrade) · GitHub

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hmmmm...

The Ruby Doc shows Enumerable as an included module of Integer (and "each" as a method) as far back as 2.4.1.

I get the same results in 3.1.1 when I query Integer.included_modules. And "5.responds_to? :each" returns false.

Perhaps someone added the Enumerable mixin in 2.4.1, and then removed it later for some good reason but forgot to update the doc?

                  \-\- Jens
···

On 2022-03-28 10:03 AM, Walter Lee Davis wrote:

And that seems to be wrong. If I look in 3.1.1, and ask Ruby:

=> ruby-3.1.1 [ arm64 ]

# => - current
# =* - current && default
# * - default

waltd@Max ~ % irb
  :001 > Integer.included_modules
  => [Comparable, PP::ObjectMixin, Kernel]
  :002 >
                  I do not see Enumerable in there...

Looks like a documentation fail to me...

Walter

On Mar 28, 2022, at 9:49 AM, Francois Buys <buys.fran@gmail.com> wrote:

I see it on this page: Class: Integer (Ruby 3.1.1)

On 28 Mar 2022, at 15:48, Walter Lee Davis <waltd@wdstudio.com> wrote:

Interesting. Not in 3.0, but if the docs say it is in 3.1, I guess I'll have to install 3.1 and see...

3.0.3 :001 > Integer.included_modules
=> [Comparable, PP::ObjectMixin, Kernel]
3.0.3 :002 >

Walter

On Mar 28, 2022, at 9:43 AM, Ricardo Franco <ricardo.krieg@gmail.com> wrote:

Class: Integer (Ruby 3.1.1)

On Mon, Mar 28, 2022 at 10:38 AM hmdne <hmdne@airmail.cc> wrote:
Can you link to the documentation where it's wrong? Integer clearly
doesn't include Enumerable, it includes Comparable.

On 3/28/22 15:35, Ricardo Franco wrote:

The documentation seems wrong. As Integer doesn't include Enumerable
and the documentation says it includes.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

Ricardo Franco Andrade

Software Engineer

email: ricardo.krieg@gmail.com
skype: ricardo.krieg
phone: +55 (86) 9569 8521
linkedin: http://br.linkedin.com/in/ricardokrieg/
github: ricardokrieg (Ricardo Andrade) · GitHub

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;