Define and change constants in a class

suggest change
class Message
  DEFAULT_MESSAGE = "Hello, world"

  def speak(message = nil)
    if message
      puts message
    else
      puts DEFAULT_MESSAGE
    end
  end
end

The constant DEFAULT_MESSAGE can be changed with the following code:

Message::DEFAULT_MESSAGE = "Hullo, world"

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents