Hello all!

A while ago, there was a discussion about a "cut" operator, which was to
avoid chained method calls with one or more methods that might return
"nil" giving a nasty error like this:

('1234'.index('6')+1).display
NameError: undefined method `+' for nil

With cut, it can be made to do this:

('1234'.index('6').cut+1).display
nil

The following implementation seems to work OK, except for one thing: since
the method after the cut goes into method_missing, it will probably have
it's parameters evaluated, which I presume is not wanted. If anyone knows
a solution to that?


class Object
        def cut
                self
        end
end

class DisinterestedClass
        def method_missing(x, y)
                nil
        end
end

class NilClass
        def cut
                DisinterestedClass.new
        end
end

('1234'.index('4').cut+1).display
puts "\n..."
('1234'.index('6').cut+1).display
puts "\n..."


Dag Allemaal!