ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "petekinnecom (Pete Kinnecom) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "petekinnecom (Pete Kinnecom)" <noreply@ruby-lang.org>
Subject: [ruby-core:122348] [Ruby Bug#21384] const_added is triggered twice when using autoload
Date: Fri, 30 May 2025 23:56:13 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-113494.20250530235613.58511@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-21384.20250529230200.58511@ruby-lang.org>

Issue #21384 has been updated by petekinnecom (Pete Kinnecom).


I see, thank you for the clarification!

----------------------------------------
Bug #21384: const_added is triggered twice when using autoload
https://bugs.ruby-lang.org/issues/21384#change-113494

* Author: petekinnecom (Pete Kinnecom)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
As the title says, I've noticed that `const_added` is invoked twice when using `autoload`. I'm wondering if this behavior is intended or perhaps a bug. Here's a small script to reproduce what I'm seeing:


``` ruby
require "tmpdir"

dir = Dir.mktmpdir

File.write(
  File.join(dir, "const.rb"),
  "class Const; end"
)

def Object.const_added(const_name)
  super.tap { puts "const_added: #{const_name}" }
end

$LOAD_PATH << dir

puts "before autoload call"
autoload :Const, "const"
puts "after autoload call"
puts Const

# Produces output:
#
# => before autoload call
# => const_added: Const
# => after autoload call
# => const_added: Const
# => Const
```




I'm seeing the behavior using the following docker containers ruby:3.2 and ruby:3.5-rc when running like so: `docker run -v ./:/home ruby:3.5-rc ruby /home/script.rb`. Thanks.




-- 
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:[~2025-05-30 23:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-29 23:02 [ruby-core:122338] " petekinnecom (Pete Kinnecom) via ruby-core
2025-05-30 15:30 ` [ruby-core:122341] " fxn (Xavier Noria) via ruby-core
2025-05-30 15:32 ` [ruby-core:122342] " fxn (Xavier Noria) via ruby-core
2025-05-30 23:56 ` petekinnecom (Pete Kinnecom) via ruby-core [this message]
2025-06-05 11:00 ` [ruby-core:122451] " mame (Yusuke Endoh) 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-113494.20250530235613.58511@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).