Project

General

Profile

Actions

Bug #9611

closed

Arithmetic operator following parentheses-less method gives ArgumentError

Added by battox (Matías Battocchia) about 10 years ago. Updated about 10 years ago.

Status:
Rejected
Target version:
-
[ruby-core:61371]

Description

It would be better to explain this with an example:

> 'a'.length -1                                                                                                          
ArgumentError: wrong number of arguments (1 for 0)
from (pry):1:in `length'

Other ways of writing this expression work as expected:

> 'a'.length() -1
=> 0

> 'a'.length-1
=> 0

> 'a'.length- 1
=> 0

> 'a'.length - 1                                                                                                         
=> 0

Updated by battox (Matías Battocchia) about 10 years ago

Even though this also happens with +, * and /, I guess it is on purpose to pass negative numbers, not a bug. My mistake.

Updated by usa (Usaku NAKAMURA) about 10 years ago

  • Status changed from Open to Rejected

Yes, this is well-known (but often misunderstood) ruby's spec.

Actions

Also available in: Atom PDF

Like0
Like0Like0