There is no equivalent of Ruby's respond_to - you have to catch MissingMethodException. E.g.
try {
value = value.toGroovy()
} catch(MissingMethodException) {}
value
instead of
if (value.respondTo("toGroovy")) {
value = value.toGroovy()
}
value
Description
There is no equivalent of Ruby's respond_to - you have to catch MissingMethodException. E.g.
try {
value = value.toGroovy()
} catch(MissingMethodException) {}
value
instead of
if (value.respondTo("toGroovy")) {
value = value.toGroovy()
}
value
Luke Daley added a comment - 12/Aug/07 02:34 AM 'respondsTo' reads more naturally. I would prefer the method to be called 'respondsTo' over 'respondTo'.
'respondsTo' reads more naturally. I would prefer the method to be called 'respondsTo' over 'respondTo'.