From: Fily Salas Date: 2011-11-09T23:46:42+09:00 Subject: How can I overwrite class variables Hi, How can I overwrite a class variable? What I have here is a class called Machine which calculates how many times a rectngle fits in a 60 x 120 rectangular shape and its working, in the code below it could fit 36 times, the problems is that I'm going to have differnet methods which are supose to overwrite @@kerf and make the calculation based on these new values but I do not know how to overwrite the class variable @@kerf. How can I overwrite variable @@kerf so that when I call method "laser (machine1.laser) the result would be 6 instead of 36 and when the method "rurret" (machine1.turret) is called the result would be 12 instead of 36? ------------------------------------ class Machine @@kerf = 0 def initialize(prt_w, prt_l) part_width = prt_w + @@kerf part_length = prt_l + @@kerf sheet_width = 60 sheet_length = 120 parts_y = sheet_width / part_width parts_x = sheet_length / part_length @total = parts_y * parts_x end def laser @@kerf = 20 puts "#{@total.floor}" end def turret @@kerf = 10 puts "#{@total.floor}" end end machine1 = Machine.new(10 , 20) machine1.laser machine1.turret ----------------------------------------- Sorry if my code doesnt make any sense but I'm practicing. Thanks a lot for your help! -- Posted via http://www.ruby-forum.com/.