Dynamic constant assignment

后端 未结 7 767
眼角桃花
眼角桃花 2020-11-28 20:31
class MyClass
  def mymethod
    MYCONSTANT = \"blah\"
  end
end

gives me the error:

SyntaxError: dynamic constant assignmen

相关标签:
7条回答
  • 2020-11-28 21:05

    You can't name a variable with capital letters or Ruby will asume its a constant and will want it to keep it's value constant, in which case changing it's value would be an error an "dynamic constant assignment error". With lower case should be fine

    class MyClass
      def mymethod
        myconstant = "blah"
      end
    end
    
    0 讨论(0)
提交回复
热议问题