ruby - Array.reject!(&:empty?) removes non-blank object -
i can't figure out why, when using reject!(&:empty?), non-empty objects removed.
example:
["example"].reject!(&:empty?) returns nil. however,
["example", ""].reject!(&:empty?) returns ["example"], should.
why?
from documentation:
equivalent
#delete_if, deleting elements self block evaluates true, but returns nil if no changes made.
if want use result of array (and less interested in changing array - use reject instead:
["example"].reject(&:empty?) # => ["example"] ["example", ""].reject(&:empty?) # => ["example"]
Comments
Post a Comment