Created
June 17, 2014 15:19
-
-
Save jeffscottbrown/676ecfb9973e1f79585f to your computer and use it in GitHub Desktop.
Map Stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mapstuff $ cat demo.groovy | |
// This is just an example to demonstrate a possibilty, | |
// not a recommendation of best practice. | |
Map.metaClass.someMethodName = { key, defaultValue -> | |
delegate.containsKey(key) ? delegate[key] : defaultValue | |
} | |
def map = [name: 'Jeff', town: 'St. Louis'] | |
def name = map.someMethodName('name', 'default value') | |
def company = map.someMethodName('company', 'default vaulue') | |
println "Name: ${name}" | |
println "Company: ${company}" | |
mapstuff $ | |
mapstuff $ groovy demo | |
Name: Jeff | |
Company: default vaulue | |
mapstuff $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment