How to change the default value of a Struct attribute?

后端 未结 6 1406
孤城傲影
孤城傲影 2020-12-17 07:43

According to the documentation unset attributes of Struct are set to nil:

unset parameters default to nil.

Is it po

6条回答
  •  情书的邮戳
    2020-12-17 08:35

    I also found this:

    Person = Struct.new "Person", :name, :happy do
      def initialize(*)
        super
        self.location ||= true
      end
    end
    

提交回复
热议问题