Stefan said:
So how can I explain to you that it *isn't*?
rescue NoMethodError has the same disadvantage as rescue StandardError;
it may catch errors that you did not intend to. e.g.:
foo = Object.new
def foo.bar
baz()
end
foo.bar->boo
=> NoMethodError: undefined method `baz'
begin
foo.bar.boo
rescue NoMethodError
end
=> nil
Somebody else here on the list uses a method 'ergo' to do what -> would
That would be me
do. Similar disadvantages as the ._methods solution.
except with less namespace pollution
I have to admit the -> keyword would be better. With ergo I have to
propagate the check to every step of the call chain:
a.b.ergo.c.ergo.d.ergo.e
where -> would allow a simple
a.b->c.d.e
(assuming that you only want to guard against b being nil)
But since other languages (e.g. PHP) use -> for method access, I think
we would see a lot of newbies blindly using -> for all method calls and
then wondering why things go awry. Maybe ".?" would be better? Or maybe
we're over-thinking and this feature isn't really used often enough to
warrant its own operator and a more verbose form like ergo is enough...
Daniel