Adding built-in methods
However simple our DSL might now look, the need to preface our method calls with GeeTwitter
is one final piece of boilerplate code that it would be nice to remove. In some of the previous examples we have used a static import to do this, but it is still not very intuitive to a non Java/Groovy programmer why we are doing this. Since we are evaluating the DSL script ourselves, rather than allowing Groovy to do it, we still have some scope to do this.
It would certainly be nicer to be able to write:
eachFollower { sendMessage it, "Thanks for taking the time to follow me!" }
This assumes that the eachFollower
method is built in to the DSL, rather than the more verbose:
GeeTwitter.eachFollower { GeeTwitter.sendMessage (it, "Thanks ...
Get Groovy for Domain-specific Languages - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.