ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "rolf (Rolf T) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "rolf (Rolf T)" <noreply@ruby-lang.org>
Subject: [ruby-core:119955] [Ruby master Bug#20871] Including methods in Enumerable doesn't make them available in Array
Date: Mon, 18 Nov 2024 07:24:06 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-110686.20241118072406.54954@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20871.20241105200917.54954@ruby-lang.org>

Issue #20871 has been updated by rolf (Rolf T).


We are running into the exact same problem. I was not able to reproduce it except as part of a Rails application. Maybe that's not exactly helpful, but hopefully this helps zoom in further on the issue. The problem seems to be introduced in Ruby 3.3.6.

A working reproduction is here: https://github.com/rolftimmermans/ruby-20871

With Ruby 3.3.6 via irb there seems to be no issue:

``` ruby
% irb                    
irb(main):001> RUBY_VERSION
=> "3.3.6"
irb(main):002> require_relative "lib/ext"
=> true
irb(main):003> [].foo
=> "foo"
```

With Ruby 3.3.6 via Rails console the bug manifests itself:

```ruby
% rails c
Loading development environment (Rails 7.1.5)
irb(main):001> RUBY_VERSION
=> "3.3.6"
irb(main):002> require_relative "lib/ext"
=> true
irb(main):003> [].foo
(irb):3:in `<main>': undefined method `foo' for an instance of Array (NoMethodError)

[].foo
  ^^^^
```

With Ruby 3.3.5 via Rails console everything is working fine:

```ruby
% rails c     
/Users/rolftimmermans/.rubies/ruby-3.3.5/lib/ruby/3.3.0/json/generic_object.rb:2: warning: /Users/rolftimmermans/.rubies/ruby-3.3.5/lib/ruby/3.3.0/ostruct.rb was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add ostruct to your Gemfile or gemspec to silence this warning.
Loading development environment (Rails 7.1.5)
irb(main):001> RUBY_VERSION
=> "3.3.5"
irb(main):002> require_relative "lib/ext"
=> true
irb(main):003> [].foo
=> "foo"
```

----------------------------------------
Bug #20871: Including methods in Enumerable doesn't make them available in Array
https://bugs.ruby-lang.org/issues/20871#change-110686

* Author: sanderd17 (Sander Deryckere)
* Status: Feedback
* ruby -v: 3.3.6
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Today, our CI pipeline started failing after the automatic update from v3.3.5 to v3.3.6.

After researching, it turned out that our core extensions to the `Array` class weren't loaded anymore.

The core-extensions code looks like this:

```ruby

module CoreExt
  module Enumerable
    def average
      sum(&:to_f) / count if any?
    end

    # def ...
  end
end

Enumerable.include CoreExt::Enumerable
```

After some debugging, it turned out that the `average` method was included in the `instance_methods` of `Enumerable`, but not in the `instance_methods` of `Array`.

Explicitly adding `Array.include CoreExt::Enumerable` fixes CI for our case.


The very strange thing is that it only happens on a release branch we are still maintaining. It doesn't happen on our main development branch (which also updated to v3.3.6 today). I have been unable to find the difference between both branches so far (they diverged a couple of months ago, but the base system is still regularly updated on both, and pretty similar).

After some digging around, I assume this commit is related to our issue: https://github.com/ruby/ruby/commit/edeb0319f7a95dfe3f9b895bcf32371dd8514726



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

  parent reply	other threads:[~2024-11-18  7:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 20:09 [ruby-core:119751] " sanderd17 (Sander Deryckere) via ruby-core
2024-11-05 20:25 ` [ruby-core:119752] " sanderd17 (Sander Deryckere) via ruby-core
2024-11-18  5:02 ` [ruby-core:119954] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-11-18  7:24 ` rolf (Rolf T) via ruby-core [this message]
2024-11-18  9:12 ` [ruby-core:119956] " rolf (Rolf T) via ruby-core
2024-11-19  8:43 ` [ruby-core:119964] " tdeo (Thierry Deo) via ruby-core
2024-11-19 14:37 ` [ruby-core:119968] " sanderd17 (Sander Deryckere) via ruby-core
2024-11-19 15:36 ` [ruby-core:119969] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-11-19 20:35 ` [ruby-core:119970] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-11-20  1:12 ` [ruby-core:119971] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-11-20 18:23 ` [ruby-core:119976] " sanderd17 (Sander Deryckere) via ruby-core
2024-11-30  6:11 ` [ruby-core:120069] " nagachika (Tomoyuki Chikanaga) via ruby-core
2025-01-15  1:49 ` [ruby-core:120682] " k0kubun (Takashi Kokubun) via ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-110686.20241118072406.54954@ruby-lang.org \
    --to=ruby-core@ml.ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).