Return nil Instead Of empty Array instance

Aug 08
2008
class Array
  def empty_and_nil
    self.empty?? nil : self
  end
end
 
result = [1,2,3].empty_and_nil # [1, 2, 3]
result = [].empty_and_nil        # nil

Comments are closed.

Calendar

August 2008
M T W T F S S
« Jul   Sep »
 123
45678910
11121314151617
18192021222324
25262728293031

Tags