开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜