Created
November 30, 2013 04:33
-
-
Save gja/7715428 to your computer and use it in GitHub Desktop.
Nil punting ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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