From: hanmac@... Date: 2017-04-03T14:19:57+00:00 Subject: [ruby-core:80546] [Ruby trunk Feature#13395] Add a method to check for not nil Issue #13395 has been updated by Hanmac (Hans Mackowiak). nobu (Nobuyoshi Nakada) wrote: > Hanmac (Hans Mackowiak) wrote: > > ~~~ ruby > > array.count(&:itself) > > ~~~ > > does work for something **similar** like that. > > IIRC, it equals to simple `array.count`. are you sure? i am currently on ruby 2.3.3 Windows ~~~ ruby [1, "bc", nil].count #=> 3 [1, "bc", nil].count(&:itself) #=> 2 ~~~ ---------------------------------------- Feature #13395: Add a method to check for not nil https://bugs.ruby-lang.org/issues/13395#change-64046 * Author: JustJosh (Joshua Stowers) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- 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: > ~~~ ruby > array = [1, 'dog', nil] > array.count(&:not_nil?) > ~~~ > vs > ~~~ ruby > array = [1, 'dog', nil] > array.reject(&:nil?).count > ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: