# How to get the variables from a class

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-variables-from-a-class/118947>\
**Category:** Ruby\
**Created:** [November 1, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/how-to-get-the-variables-from-a-class/118947 "2007-11-01T17:24:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [November 1, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/how-to-get-the-variables-from-a-class/118947/1 "2007-11-01T17:24:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [November 1, 2007, 5:50pm UTC](https://www.ruby-forum.com/t/how-to-get-the-variables-from-a-class/118947/2 "2007-11-01T17:50:15Z")

</div>

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

tuest2=::toast.new(‘black’,‘biggest’) # from Appliances

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [November 1, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/how-to-get-the-variables-from-a-class/118947/3 "2007-11-01T17:52:12Z")

</div>

The error is:  
wrong number of arguments

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [November 1, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/how-to-get-the-variables-from-a-class/118947/4 "2007-11-01T21:53:31Z")

</div>

On Nov 1, 2007, at 12:24 PM, Mario R. wrote:

> * * *
> 
> 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
