How to inherit from NilClass or how to simulate similar function
I just want to use Null Object Design Pattern, but I found I can inherit from NilClass. I can write a method "nil?" and return false but what if user write code below if null_object puts "shouldn't be here" end For clarify what I try to do is: record = DB.find(1) # if it can not find record 1, the bellow code should not raise exception record.one_attr # and what's more if record puts "shouldn't be here" end # I don't want to override all NilClass An approach that may work for you is to overide the method #nil? in your Null object. This means that in your code to test for null you have to use