Project

General

Profile

Actions

Feature #13979

closed

Ruby doesn't give error on keyword arguments that you can't refer to

Added by asterite (Ary Borenszweig) over 6 years ago. Updated over 6 years ago.

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

Description

You can't use keywords as names for normal arguments. For example all of these give a syntax error:

def foo(class); end
def foo(def); end
def foo(if); end
# ... other keywords too

The reason is that there's no way to refer to these names because they are keywords.

However, we can use these names for keyword arguments. All of these work:

def foo(class: 1); end
def foo(def: 1); end
def foo(if: 1); end

But I think they should give a syntax error, because for example I can't refer to the argument "class" in the first line (same reason why the first snippet gives a syntax error).

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0