Project

General

Profile

Actions

Bug #18752

closed

defined? String.instance_method(:abcdefg) will return a "method" string instead nil.

Added by zw963 (Wei Zheng) over 2 years ago. Updated over 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:108380]

Description

Please check following IRB example which can be reproduce on ruby 3.1.0

3.1.0 :012 > defined? String.instance_method(:abcdefg)
 => "method" 
3.1.0 :013 > defined? String.instance_method(:abcdefg111111111111)
 => "method" 
3.1.0 :014 > defined? String.instance_method(:abcdefg22222222222)
 => "method" 
3.1.0 :015 > defined? String.instance_method(:what_ever_not_exists_method_name_always_return_method?)
 => "method" 
3.1.0 :016 > String.instance_method(:what_ever_not_exists_method_name_always_return_method?)
(irb):16:in `instance_method': undefined method `what_ever_not_exists_method_name_always_return_method?' for class `String' (NameError)                                                                                   
        from (irb):16:in `<main>'                                                                    
        from /home/common/.rvm/rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
        from /home/zw963/.rvm/rubies/ruby-3.1.0/bin/irb:25:in `load'                        
        from /home/zw963/.rvm/rubies/ruby-3.1.0/bin/irb:25:in `<main>'                      
3.1.0 :017 > 
3.1.0 :018 > defined? AAA
 => nil 
3.1.0 :019 > AAA
(irb):19:in `<main>': uninitialized constant AAA (NameError)
        from /home/common/.rvm/rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
        from /home/zw963/.rvm/rubies/ruby-3.1.0/bin/irb:25:in `load'
        from /home/zw963/.rvm/rubies/ruby-3.1.0/bin/irb:25:in `<main>'
3.1.0 :020 > 

                 

If the method not be defined on String#, should it return nil instead, as const does, right?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0