Ruby program to implement setter method using 'attr_writer' accessor
class Sample
# constructor
def initialize(val)
@ins_var = val;
end
# Getter method
attr_reader:ins_var
# accessor set method
attr_writer :ins_var
end
obj = Sample.new("Hello");
val = obj.ins_var;
print "Value is: ",val,"\n";
obj.ins_var = "Hii";
val = obj.ins_var;
print "Value is: ",val,"\n";
Output:
Value is: Hello
Value is: Hii
