Project

General

Profile

Actions

Feature #13395

open

Add a method to check for not nil

Added by JustJosh (Joshua Stowers) almost 7 years ago. Updated over 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:80529]

Description

There does not seem to be a method in Ruby to check if an object is not nil.
Such a method could help with readability.

Example:

array = [1, 'dog', nil]
array.count(&:not_nil?)

vs

array = [1, 'dog', nil]
array.reject(&:nil?).count

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #12075: some container#nonempty?Feedbackmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0