Groovy web console

subscribe to the feed Subscribe
to this
site
MetaProgramming (via #groovywebconsole)
tweet this snippet Tweet
this
script

MetaProgramming

Published 5 months ago by Shane
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
//Using metaclass to create new methods on something

def limitMyListPlease(List x, Integer i){  return x[0..i] }  

List.metaClass.limit = { i -> limitMyListPlease(delegate,i) }  

["a","b","c","d","e"].limit(3)