Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-beta-2
-
None
-
None
Description
I know Sam mentioned this so I thought I'd raise a JIRA issue before I forgot.
Hacking the parser so that /this|is|a|regexp/ could be embedded inside any groovy code (i.e. / followed by text ending in /) represents a regexp. Ruby uses this encoding mechanism. If that works out OK then we can support native regexp like Ruby & Perl.
I'm thinking we should have some polymorphic new method like 'matches' which Object can support (which defaults to equals) but which things like Collections or Ranges can use 'contains' and things like regexp can mean 'matches'. Or Class could use matches to mean 'instanceof'
Then switch statements could use 'matches' to allow neat switches...
switch (foo) {
case SomeClass:
case 0..10:
case /some|regex/:
case [1, 4, 6]:
}
etc