Overview of enhancements
Gosu provides a feature called enhancements, which supports adding functions and properties to other types. Enhancements are especially powerful for enhancing native Java types, and types defined in other people’s code.
For example, Gosu includes built-in enhancements on collection classes and interfaces, such as java.util.List, that improve power and readability of collections code. For example, the following code takes a list of String objects, and uses a block to sort the list by the length of each String. The code then uses another block in the iteration across the result list to print each item:
strings.sortBy(\ str -> str.length).each(\ str -> print(str))The sortBy and each methods in this example are
Gosu enhancement methods on the List
interface. Both methods return the result list, which makes them useful
for chaining methods in series.
See also
