Issue Details (XML | Word | Printable)

Key: GROOVY-502
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Paul King
Reporter: Thomas Heller
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

Adding instance methods to classes

Created: 26/May/04 11:06 AM   Updated: 18/Jun/07 05:38 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1-beta-2

Time Tracking:
Not Specified


 Description  « Hide
Sam introduced the "use" keyword but I'd like to have a somewhat more permanent ways because "use" is quite noisy in scripts and can get overused quite easily.

I quickly developed a simple way to add methods just like the DefaultGroovyMethods does. Its not perfect cause it requires a system property but it works quite nicely.

See patch&testcase here:

http://lists.codehaus.org/pipermail/groovy-dev/2004q2/002055.html



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Bing Ran added a comment - 26/May/04 11:30 AM
A couple of ways to avoid using a special system property:

1. The Groovy runtime designate a special package (e.g., groovy.lang.extension) as a namespace where any class in the package is considered Groovy runtime extensions. Anytime a user would add his own new methods for java classes, he/she creats a new class in that namespace.

2. The Groovy runtime designate a special directory in the fielsystem and any class files or jars files are searched for
extensions. This is similar to java lib/ext mechanism.

Of course, all these are subjected to groovy runtime security policy.


Paul King added a comment - 18/Jun/07 05:38 AM
Now handled by ExpandoMetaClass, see http://groovy.codehaus.org/ExpandoMetaClass