Reputation: 187499
In Groovy, I can write code such as:
assert 1 in [1,2,3]
assert "foo" in "foo"
assert 2 in 1..4
Is there some way that I can overload the 'in' operator for my own classes? If so, which method should I implement?
Thanks!
Upvotes: 2
Views: 268
Reputation: 171084
You need to overload the isCase method, ie:
class Example {
def isCase( o ) {
true
}
}
def c = new Example()
println( "woo" in c )
prints true
Upvotes: 4