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

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -