ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: alanwucanada@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91722] [Ruby trunk Bug#15646] method_defined? inside method_added behaves differently for `initialize`
Date: Fri, 08 Mar 2019 21:05:09 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-76998.20190308210505.0178e57f458e562b@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15646.20190308205623@ruby-lang.org

Issue #15646 has been updated by alanwu (Alan Wu).


Ah, I didn't know `initialize` is always private:

```ruby
irb(main):001:0> class A
irb(main):002:1>   def initialize
irb(main):003:2>   end
irb(main):004:1> end
=> :initialize
irb(main):005:0> A.new.initialize
Traceback (most recent call last):
        4: from /opt/rubies/2.6.1/bin/irb:23:in `<main>'
        3: from /opt/rubies/2.6.1/bin/irb:23:in `load'
        2: from /opt/rubies/2.6.1/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        1: from (irb):5
NoMethodError (private method `initialize' called for #<A:0x00007faedb0bf428>)
```

----------------------------------------
Bug #15646: method_defined? inside method_added behaves differently for `initialize`
https://bugs.ruby-lang.org/issues/15646#change-76998

* Author: alanwu (Alan Wu)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.7.0dev (2019-03-08 trunk 67194) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Repro:
```ruby
class MethodAddedSpecialCase
  def self.method_added(name)
    puts "#{name} added, method_defined?: #{method_defined?(name)}"
  end

  def hello
  end

  def initialize
  end
  
  def world
  end
end
```

Output:
```
hello added, method_defined?: true
initialize added, method_defined?: false
world added, method_defined?: true
```



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2019-03-08 21:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15646.20190308205623@ruby-lang.org>
2019-03-08 20:56 ` [ruby-core:91721] [Ruby trunk Bug#15646] method_defined? inside method_added behaves differently for `initialize` alanwucanada
2019-03-08 21:05 ` alanwucanada [this message]
2019-03-08 23:45 ` [ruby-core:91726] " nobu
2019-03-10  0:44 ` [ruby-core:91732] " alanwucanada
2019-03-10  6:25 ` [ruby-core:91733] " nobu

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-list from there: mbox

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

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

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

  git send-email \
    --in-reply-to=redmine.journal-76998.20190308210505.0178e57f458e562b@ruby-lang.org \
    --to=ruby-core@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 read-only IMAP folder(s) and NNTP newsgroup(s).