开发者

Rails - Iterating through method names

开发者 https://www.devze.com 2023-03-04 20:39 出处:网络
I\'m trying to figure out how to iterate through method names in my controller. This is what I have so far but of course this won\'t work. I\'ve seen other posts about using \'send\'. But couldn\'t ge

I'm trying to figure out how to iterate through method names in my controller. This is what I have so far but of course this won't work. I've seen other posts about using 'send'. But couldn't get that to work right. Any suggestions?

@someMethods = {
 开发者_JAVA百科 '0' => 'methodone',
  '1' => 'methodtwo'
}

for count in 0..1
  @someObject[count] = Trucks.@someMethods["#{count}"](params[:color])
end


@someMethods.each do |count, method|
  @someObject[count] = Trucks.send(method, params[:color])
end
0

精彩评论

暂无评论...
验证码 换一张
取 消