Project

General

Profile

Feature #10406

Method starting with a capital is not detected when parentheses and receiver are omitted

Added by sawa (Tsuyoshi Sawada) almost 3 years ago. Updated almost 3 years ago.

Status:
Rejected
Priority:
Normal
Target version:
[ruby-core:65810]

Description

A method whose name starts with a capital is not detected when parentheses and receiver are omitted.

def Foo; puts "foo" end
Foo # => uninitialized constant Foo

If I disambiguate it as a method, then the method is detected:

Foo() # => foo

This kind of consideration if unnecessary if the method name does not start with a capital.

def foo; puts "foo" end
foo # => foo

So I expect method Foo to be detected without explicit receiver and arguments (unless there is a constant with the same name).

def Foo; puts "foo" end

I first thought this as a bug. If it is not a bug, then I would like to ask this as a feature request.

History

#1 [ruby-core:65811] Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

  • Tracker changed from Bug to Feature
  • Category set to syntax
  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)
  • Target version set to Next Major

It's a ruby's naming rule.

#2 [ruby-core:65812] Updated by mame (Yusuke Endoh) almost 3 years ago

I believe this is intentional. Otherwise, we would become unable to refer Array, Integer, Float, String, and Hash classes because of Kernel#Array and so on ;-)

--
Yusuke Endoh mame@ruby-lang.org

#3 [ruby-core:65814] Updated by sawa (Tsuyoshi Sawada) almost 3 years ago

Yusuke Endoh wrote:

I believe this is intentional. Otherwise, we would become unable to refer Array, Integer, Float, String, and Hash classes because of Kernel#Array and so on ;-)

Just like local variables have precedence over method look up, I expect that constants have precedence over method look up, so I don't think that would be a problem.

#4 [ruby-core:65815] Updated by mame (Yusuke Endoh) almost 3 years ago

Oops, I see. Sorry for the noise!

--
Yusuke Endoh mame@ruby-lang.org

#5 [ruby-core:65817] Updated by matz (Yukihiro Matsumoto) almost 3 years ago

  • Status changed from Assigned to Rejected

Unlike local variables, constants are not resolved statically. That's the reason behind this behavior.
If you have further demand, reopen the issue.

Matz.

Also available in: Atom PDF