Skip to content

Instantly share code, notes, and snippets.

@ToQoz
Created July 26, 2011 07:44
Show Gist options
  • Save ToQoz/1106211 to your computer and use it in GitHub Desktop.
Save ToQoz/1106211 to your computer and use it in GitHub Desktop.
pythonでrubyのdefine_method的なことをやってみる。
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