Project

General

Profile

Actions

Feature #17290

closed

Syntax sugar for boolean keyword argument

Added by sawa (Tsuyoshi Sawada) over 3 years ago. Updated about 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:100630]

Description

We frequently use keyword arguments just to pass true value out of the truthy/falsy options given. And in many such cases, the falsy option is set as the default, and only the truthy value is ever passed explicitly. I propose to have a syntax sugar to omit the value of a keyword argument. When omitted, it should be interpreted with value true.

gets(chomp:)
CSV.parse(" foo var ", strip:)

should be equivalent to

gets(chomp: true)
CSV.parse(" foo var ", strip: true)

Additionally, we may also extend this to pragmas.

# frozen_string_literal:

to be equivalent to:

# frozen_string_literal: true
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0