From: Gregory Brown Date: 2007-06-24T12:38:41+09:00 Subject: Re: Newbie Question Passing variables to methods On 6/23/07, Starke wrote: > Im trying to set up a method and pass a varible to it then out put the > new manipulated varible back out. Here is what I have > > > --------------------------------- > var1 = 'test' > > def change var_in > puts var_in > var_in = 'test1' > puts var_in > end > > change var1 > > ----------------------------------- > > As you can see, I pass in var1 into the method and then I change the > value to 'test1'. I would like to method to go back and update var1, > so that if passed into another method it reflects the change that > method change var_in did. Does this make since? Im new to > programming. Hi. What you are talking about are instance variables. Let's move your print statements outside of your method: #--- @var1 = "test" puts @var1 def change @var1 = "test1" end change puts @var1 #--- or, if you want to pass the value into your method: #--- def change(value) @var1 = value end change 'something' puts @var1 #--- You'll want to pick up a basic understanding of scoping, data encapsulation, and object oriented design. You might start with some simple tutorials that help you learn by example, such as TryRuby: http://tryruby.hobix.com/ The first edition of Programming Ruby is also available free online, and is a good book. Once you get somewhat familiar, you might want to pick up the second edition as a reference http://www.rubycentral.com/book/ And of course, if you run into problems, post here. :) Best of luck, -greg