开发者

Rails - What does the instance :topic mean in this line of code?

开发者 https://www.devze.com 2023-02-27 10:00 出处:网络
Where it says :topic, what is that doing? From what I can understand :topic could also be :posts if that is your model. But why is it specified there exactly? Thanks

Where it says :topic, what is that doing? From what I can understand :topic could also be :posts if that is your model. But why is it specified there exactly? Thanks

 def favorable(opts={})

  # favorable_type
  type = opts[:type] ? opts[:type] : :topic  开发者_StackOverflow中文版
  type = type.to_s.capitalize


:topic is a symbol, which is basically a string. So, if there's no :type key in the opts hash, type = "Topic".

I suppose they're using :topic instead of "Topic" because the opts[:type] would return a symbol, maybe :whatever and they want to set type to "Whatever".

0

精彩评论

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