Created
July 26, 2011 07:44
-
-
Save ToQoz/1106211 to your computer and use it in GitHub Desktop.
pythonでrubyのdefine_method的なことをやってみる。
This file contains 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
lang_list = ["python", | |
"ruby"] | |
class Language(): | |
pass | |
for lang in lang_list: | |
def _get_language(self, lang=lang): | |
return "[language] %s" % (lang) | |
setattr(Language, "get_" + lang, _get_language) | |
language = Language() | |
print language.get_python() #=> [language] python | |
print language.get_ruby() #=> [language] ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment