4 ms·
I'm not sure I like it, but this works def nil.method_missing(*args, &block); end So now you can call nil.whatever.you.like and get nil. It's also still f
by mcobrien 15y ago
I'm not sure I like it, but this works
def nil.method_missing(*args, &block); end
So now you can call nil.whatever.you.like and get nil. It's also still falsy, but now every nil value in your app silently works and doesn't throw an error.
It's both impressive and scary that Ruby lets you (or that new contractor you're not sure about) change the fundamentals of the language in one line of code.
- raganwald 15y agoSome consequences: https://github.com/raganwald/homoiconic/blob/master/2009-02-02/hopeless_egocentricity.md https://github.com/raganwald/homoiconic/blob/master/2009-02-...
- bodhi 15y agoI recall that this was the default action of Smalltalk? I can't find a reference though, so I am very likely incorrect. In Objective-C nil will absorb any messages too, see the section "Sending Messages to nil" in http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Chapters/ocObjectsClasses.html http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/...
- deleted 15y ago[deleted]
- spooneybarger 15y agoIt isn't the default action in smalltalk. nil does not silently absorb messages in smalltalk.