Created
July 19, 2013 01:48
-
-
Save yusukeaiko/6034486 to your computer and use it in GitHub Desktop.
動的なメソッドの呼び出し ref: http://qiita.com/Vit-Symty/items/520970885137db421ac0
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
def get_id | |
return 256 | |
end | |
def get_name | |
return 'エナジー炭酸 がぶ飲み POWER SQUASH' # いまハマってる | |
end | |
# nameが欲しい | |
data_type = :name | |
# caseで処理を分ける | |
case data_type | |
when :id then p get_id | |
when :name then p get_name |
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
def get_id | |
return 64 | |
end | |
def get_name | |
return 'A&W ROOT BEER' # ホントはこっちのほうが好き | |
end | |
# nameが欲しい | |
data_type = 'name' | |
#sendでメソッドを呼び出す | |
p send("get_#{data_type}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment