Created
October 30, 2009 00:32
-
-
Save fumokmm/221986 to your computer and use it in GitHub Desktop.
テンプレートを置き換えるデモです。
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
def template = '○○と●●●は違う' | |
def list = ['○○', '●●●'] | |
def translator = list.inject([:]){ result, item -> result[item] = getList(item); result } | |
// こうなる↓ | |
//def translator = [ | |
// '○○' : ['1', '2', '3', '4', '5'], | |
// '●●●' : ['あああ', 'いいい', 'ううう', 'えええ', 'おおお'] | |
//] | |
([template] * 5).collect{ tmpl -> | |
translator.each { tmpl = tmpl.replace( it.key, it.value.sort(){ Math.random() }.pop() ) }; tmpl | |
} | |
def getList(str) { | |
if (str == '○○') return ['1', '2', '3', '4', '5'] | |
if (str == '●●●') return ['あああ', 'いいい', 'ううう', 'えええ', 'おおお'] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment