Use find to initialize a constant?

前端 未结 3 2046
终归单人心
终归单人心 2021-01-28 09:28

Something like this:

class Category

   SOME_CATEGORY = find_by_name(\"some category\")

end

Category::SOME_CATEGORY
tried wi

3条回答
  •  生来不讨喜
    2021-01-28 09:46

    What do you want to do?

    Maybe:

    class Category
      def self.some_category
        Category.find_by_name("some category")
      end
    end
    

    So you can call:

    Category.some_category
    => 
    

提交回复
热议问题