How to get the variables from a class

M

mario

I have this code:

----------------------
require 'appliances'
class Toast<Appliances
def toast(hole,size,seconds,quantity)
self.turn_on(seconds,quantity)
self.chooser(hole,size)
end
end
----------------------

And from another file:

---------------------
require 'toast'
tuest1=::toast.new('white','big') # from Appliances
tuest1.buy('Bread','10') # from Appliances
tuest1.toast('1','200','120','2')
-----------------

Now I want to create a new variable that automatically has the same
values ('1','200','120','2' in this case) than the variable tuest1 in
tostar:

tuest2.toast=tuest1.toast

But it doesn't work.

Anybody knows how can I do it?

Thank you.
 
M

mario

I forgot it, before I did tuest2.toast=tuest1.toast I did:

tuest2=::toast.new('black','biggest') # from Appliances
 
M

m_goldberg

I have this code:

----------------------
require 'appliances'
class Toast<Appliances
def toast(hole,size,seconds,quantity)
self.turn_on(seconds,quantity)
self.chooser(hole,size)
end
end
----------------------

And from another file:

---------------------
require 'toast'
tuest1=::toast.new('white','big') # from Appliances
tuest1.buy('Bread','10') # from Appliances
tuest1.toast('1','200','120','2')
-----------------

Now I want to create a new variable that automatically has the same
values ('1','200','120','2' in this case) than the variable tuest1 in
tostar:

tuest2.toast=tuest1.toast

You don't show enough code for me to do more than make a guess, but
providing

tuest1=::toast.new('white','big')

is really a typo for

tuest1=Toast.new('white','big')

and providing Toast#initialize along with Appliance#buy and
Toast#toast have set up all the instance variables properly, then

tuest2 = tuest1.dup

should do it.

Regards, Morton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,270
Messages
2,571,339
Members
48,029
Latest member
Anchorman2022

Latest Threads

Top