【发布时间】:2017-07-16 09:05:39
【问题描述】:
我似乎无法关注this answer,但可能与我想要实现的目标不同。
我有一个字符串,那个字符串有时可能不同,我需要把那个字符串转换成一个定义好的方法名:
action = "get_name"
# The method
def get_name
puts "James"
end
# Calling the method
action # => undefined method `action' for main:Object
action 可以是我定义的任何方法,名称为字符串格式。我可以说action.to_method,你明白我的意思;)
我觉得我不能说action.to_sym?
【问题讨论】:
标签: ruby-on-rails ruby