groovy

There is no equivalent of Ruby's respond_to - you have to catch MissingMethodException

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 1.1-beta-2
  • Fix Version/s: 1.1-rc-2
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

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

Activity

Hide
Luke Daley added a comment -

'respondsTo' reads more naturally. I would prefer the method to be called 'respondsTo' over 'respondTo'.

Show
Luke Daley added a comment - 'respondsTo' reads more naturally. I would prefer the method to be called 'respondsTo' over 'respondTo'.
Hide
Paul King added a comment -

Duplicate of GROOVY-2109.

Show
Paul King added a comment - Duplicate of GROOVY-2109.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: