Project

General

Profile

Actions

Feature #13395

open

Add a method to check for not nil

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

Status:
Open
Priority:
Normal
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

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

Also available in: Atom PDF