Project

General

Profile

Actions

Feature #15445

open

Reject '.123' in Float() method

Added by mrkn (Kenta Murata) about 5 years ago. Updated about 5 years ago.

Status:
Open
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.

Updated by duerst (Martin Dürst) about 5 years 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) about 5 years 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) about 5 years 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).

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0