From: brabuhr@... Date: 2008-12-31T06:26:26+09:00 Subject: Re: Ruby Noobie needs some help On Tue, Dec 30, 2008 at 3:49 PM, r wrote: > Hello, > I am coming from the python world and trying to learn ruby. Why does > this throw an error? > > #testscript.rb > cams = ['cam1', 'cam2', 'cam3'] > def function(s) > puts s > for x in cams > print x > end > end > test() Two problems: * test() is not defined anywhere? * The variables named "cams" in the function definition and outside of it are local variables in different scopes. One option would be to use an instance variable (@cams): @cams = %w{ cam1 cam2 cam3 } def function(s) puts s for x in @cams print x end end function("foo") #=> "foo\ncam1cam2cam3"