How make a variable public final in Ruby -
i create class during initialization of object of class assign provided value 1 of variables, in such way can't changed. example:
person = person.new("tom") person.name #=> tom person.name = "bob"
this should raise error or:
person.name #=> tom -> still
class person def initialize name @name = name end attr_reader :name end person = person.new("tom") person.name #=> tom begin person.name = "bob" rescue puts $!.message # => undefined method error end person.name #=> tom
Comments
Post a Comment