How to convert a string to a constant in Ruby?

前端 未结 5 515
有刺的猬
有刺的猬 2020-11-30 02:36

How to convert the string \"User\" to User?

5条回答
  •  囚心锁ツ
    2020-11-30 03:28

    If you have ActiveSupport loaded (e.g. in Rails) you can use

    "User".constantize
    

提交回复
热议问题