I want to redefine smalltalk’s nil to work like the one in objective-c. So when nil receives a message that it can’t handle, it returns nil. Now I know that nil is just a shortcut for UndefinedObject but is there anything like method_missing in Ruby so I can redefine it in UndefinedObject to always return nil?
I want to redefine smalltalk’s nil to work like the one in objective-c .
Share
The method you are looking for is called
doesNotUnderstand:in Smalltalk. You can indeed implement:However, keep in mind that this affects the complete system and might have subtle side effects or introduce bugs in other parts of the system.
Also note that
UndefinedObjectis not a primitive type, but a normal class inheriting fromObject. Therefornilalready understands a large number of messages and might not behave as you would expect coming from Objective-C.