19
Oct
09

a way to reimplement the with statement in groovy



class G
{
   def nwith(closure) {
       closure.delegate = this
       closure()   
   }
   
   def test_print()
   {
       println "whatever"
   }
}

a = new G()
a.nwith {
    test_print()
}

I named my “with” statement “nwith”. The thing is, you need to set who the closure delegates to, and then call it. From there on, all the statements written execute in the context of that object.

Advertisements

0 Responses to “a way to reimplement the with statement in groovy”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Blog Stats

  • 223,848 hits

%d bloggers like this: