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

Multiplication Table In AoH Structure

Aug 03
2008
mt = Array.new(10) { |e| Hash.new { |h,k| h[k] = k * e } }
 
mt[1][2] => 2
mt[2][2] => 4
mt[5][4] => 20
mt[9][5] => 45

Calendar

February 2012
M T W T F S S
« Sep    
 12345
6789101112
13141516171819
20212223242526
272829  

Tags