Skip to content

Instantly share code, notes, and snippets.

@gja
Created November 30, 2013 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gja/7715428 to your computer and use it in GitHub Desktop.
Save gja/7715428 to your computer and use it in GitHub Desktop.
Nil punting ruby
class NilClass
include Enumerable
def [](index)
self
end
def merge(hash)
hash.dup
end
def each
end
end
array = nil
array.map { |a| a + 2 } # => []
array[4] # => nil
array.merge(:foo => :bar) # => {:foo => :bar}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment