Excuse a newbee's enthusiasm, but this is really cool. It makes some
code that would have had to treat nil specially.
class NilClass
def each
yield(self)
end
def length
0
end
end
a = nil
a.each {|a| puts a.class }
Doing it at the Object level is even more handy for the what I was
playing with.
class Object
def each
yield(self)
end
def length
if self == nil then 0 else 1 end
end
end
a = nil
a.each {|a| puts a.length }
So every Object has an each method, which yields itself and has a
length of 1, so everything can be treated like an array.
Really neat language.