Project

General

Profile

Feature #15445

Reject '.123' in Float() method

Added by mrkn (Kenta Murata) 6 months ago. Updated 6 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:90650]

Description

Since ruby 1.8, Ruby occurs a syntax error for "." floating literal.
But Float() method accepts such form now.

I propose to reject "." form even in Float() method.

History

Updated by duerst (Martin Dürst) 6 months ago

I seem to remember from the book (http://exceptionalruby.com/) by Avdi Grimm that in general, methods that have the same name as classes are more tolerant than other constructors. If I remember correctly, and this is by design, then we should leave it as is.

Updated by shevegen (Robert A. Heiler) 6 months ago

On a side note, perhaps we should add Float() to this document:

https://ruby-doc.org/core-2.5.3/Float.html

I understand that this is not part of class Float itself; but it uses
the same name (just distinguishes with the () for method call). It
may not have to be explained in that document, but a link to
where this may be explained may be helpful for people.

I would also recommend to put this information somewhere in
the official documentation, ideally after matz could comment
on it (since only matz fully knows the intent behind Float() and
the other methods) - I note this down only so that we can find
this in the official documentation as well. Nothing against the
book, mind you, but I believe that the main ruby documentation
site would be the ideal place for such documentation.

Updated by duerst (Martin Dürst) 6 months ago

duerst (Martin Dürst) wrote:

I seem to remember from the book (http://exceptionalruby.com/) by Avdi Grimm that in general, methods that have the same name as classes are more tolerant than other constructors. If I remember correctly, and this is by design, then we should leave it as is.

I have just confirmed the above with Avdi's book (p. 62).

Also available in: Atom PDF