What's the difference between a string and a symbol in Ruby?

后端 未结 10 1312
说谎
说谎 2020-11-28 06:52

What\'s the difference between a string and a symbol in Ruby and when should I use one over the other?

10条回答
  •  暖寄归人
    2020-11-28 07:39

    Case where symbol can be disaster. Lets say you have params.map(&:to_sym) in your rails controller . Now here if you are converting the data provided by the user to symbol due to some reason then it could be dangerous. If the data provided by the user is too large and as we know that symbol is not a garbage collector, you might end up exhausting your server's memory which can takedown your website.

提交回复
热议问题