Paul King | 24 Jun 15:17

[groovy-dev] proposed minor breaking change: isCase for Gstring


At the moment if we run this script:

def one = 'one'
def two = 'two'

switch('onetwo') {
  case 'onetwo': println true
  default: println false
}

switch("$one$two") {
  case 'onetwo': println true
  default: println false
}

switch('onetwo') {
  case "$one$two": println true
  default: println false
}

switch("one${two}") {
  case "${one}two": println true
  default: println false
}

it prints:

true
true
false
true

I propose that we add an isCase method for GString which just
calls toString() on the GString and then calls isCase on that.

The above script will then print true in all cases.

This is a breaking change for anyone relying on the 'broken'
behavior. Anyone wanting the most natural behavior for this
scenario would probably be calling toString() on the GString
anyway which will still work but no longer be required.

Can anyone see any gotchas with this proposal?

Thanks,

Paul.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane