meso_2600 meso_2600 - 4 months ago 33
Ruby Question

How make a variable public final in Ruby

I would like to create a class that during initialization of an Object of this class would assign provided value to one of the variables, in such way it can't be changed.
For example:

person ="Tom") #=> Tom = "Bob"

this should raise an error or: #=> Tom -> still

class Person
  def initialize name
    @name = name
  attr_reader :name

person ="Tom")         #=> Tom
begin = "Bob"
  puts $!.message   # => Undefined method error
end         #=> Tom