From: Emeka Patrick Date: 2012-06-21T17:30:36+09:00 Subject: Re: New to Ruby - Scope Question Thanks for getting back to me as well Jan. Was using Sublime Text 2 and doing builds in that after entering code, but recently switched over to trying to do more via IRB, which I feel is giving me a deeper understanding, but I seem to be making more mistakes in. Going to step up my meticulousness! Jan E. wrote in post #1065483: > Hi, > > Emeka Patrick wrote in post #1065478: >> Can someone explain why this is so. I guess I don't NEED to know why, >> but I'd like to understand it a bit better if possible. Thanks! > > The question has already been answered, but you can actually try out > things like that yourself: > > x = 123 > def f() > puts x > end > f() > > Since you get an error for an undefined local variable or method, Ruby's > methods obviously don't see outer variables. > > And for the other question: > > def g() > a = 123 > end > g() > puts a > > Again you get an error. So this doesn't work either. -- Posted via http://www.ruby-forum.com/.