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?
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?
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?
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>
>
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
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.
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.
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.
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.
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.