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

July 2010
M T W T F S S
« Apr    
 1234
567891011
12131415161718
19202122232425
262728293031  

Tags