ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91721] [Ruby trunk Bug#15646] method_defined? inside method_added behaves differently for `initialize`
       [not found] <redmine.issue-15646.20190308205623@ruby-lang.org>
@ 2019-03-08 20:56 ` alanwucanada
  2019-03-08 21:05 ` [ruby-core:91722] " alanwucanada
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: alanwucanada @ 2019-03-08 20:56 UTC (permalink / raw)
  To: ruby-core

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

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

* 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:
```
initialize added, method_defined?: false
hello added, method_defined?: true
world added, method_defined?: true
```



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:91722] [Ruby trunk Bug#15646] method_defined? inside method_added behaves differently for `initialize`
       [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
  2019-03-08 23:45 ` [ruby-core:91726] " nobu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: alanwucanada @ 2019-03-08 21:05 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:91726] [Ruby trunk Bug#15646] method_defined? inside method_added behaves differently for `initialize`
       [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 ` [ruby-core:91722] " alanwucanada
@ 2019-03-08 23:45 ` nobu
  2019-03-10  0:44 ` [ruby-core:91732] " alanwucanada
  2019-03-10  6:25 ` [ruby-core:91733] " nobu
  4 siblings, 0 replies; 5+ messages in thread
From: nobu @ 2019-03-08 23:45 UTC (permalink / raw)
  To: ruby-core

Issue #15646 has been updated by nobu (Nobuyoshi Nakada).


I think it is documented somewhere, but can't remember where it is now.

Anyway, these methods are always defined as private, unless singleton methods.
`initialize`, `initialize_copy`, `initialize_clone`, `initialize_dup`, `respond_to_missing?`


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

* 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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:91732] [Ruby trunk Bug#15646] method_defined? inside method_added behaves differently for `initialize`
       [not found] <redmine.issue-15646.20190308205623@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-03-08 23:45 ` [ruby-core:91726] " nobu
@ 2019-03-10  0:44 ` alanwucanada
  2019-03-10  6:25 ` [ruby-core:91733] " nobu
  4 siblings, 0 replies; 5+ messages in thread
From: alanwucanada @ 2019-03-10  0:44 UTC (permalink / raw)
  To: ruby-core

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


This behavior is from [Feature #6539]. Do you remember why these methods are made to be always private, instead of setting them to be private in Kernel only?
I don't think this rule make sense for BasicObject classes since they don't have `#dup` and `#clone` and `#respond_to?`:
```ruby
class A < BasicObject
  public

  def initialize_dup
  end
end

A.new.initialize_dup # private method `initialize_dup' called
```
 

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

* 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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:91733] [Ruby trunk Bug#15646] method_defined? inside method_added behaves differently for `initialize`
       [not found] <redmine.issue-15646.20190308205623@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-03-10  0:44 ` [ruby-core:91732] " alanwucanada
@ 2019-03-10  6:25 ` nobu
  4 siblings, 0 replies; 5+ messages in thread
From: nobu @ 2019-03-10  6:25 UTC (permalink / raw)
  To: ruby-core

Issue #15646 has been updated by nobu (Nobuyoshi Nakada).


`initialize` isn't involved in [Feature #6539].
It has been always private since more earlier days, 1.1 at least.

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

* 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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-10  6:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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 ` [ruby-core:91722] " alanwucanada
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

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).