Skip to content

Instantly share code, notes, and snippets.

@yusukeaiko
Created July 19, 2013 01:48
Show Gist options
  • Save yusukeaiko/6034486 to your computer and use it in GitHub Desktop.
Save yusukeaiko/6034486 to your computer and use it in GitHub Desktop.
動的なメソッドの呼び出し ref: http://qiita.com/Vit-Symty/items/520970885137db421ac0
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
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