Using the Immutable_struct gem

require 'immutable_struct'

c = ImmutableStruct.new(:name, :max_speed)
ship = c.new('Enterprise', 'Warp 9')
puts ship.max_speed # => Warp 9
ship.max_speed = '299792458 m/s' # raises NoMethodError

Resources

Tags:
Source:
1129hrs.txt
Published:
07-07-2014 11:29