Variables in ruby method names

前端 未结 4 1155
感情败类
感情败类 2021-01-30 00:50

I have the following code:

for attribute in site.device_attributes
  device.attribute
end

where I would like the code to substitute the value o

4条回答
  •  天命终不由人
    2021-01-30 01:44

    The "send" method should do what you're looking for:

    object = "upcase me!"
    method = "upcase"
    object.send(method.to_sym) # => "UPCASE ME!"
    

提交回复
热议问题