From: dblack@... Date: 2007-07-24T18:50:39+09:00 Subject: Re: Static variables in Ruby. Hi -- On Tue, 24 Jul 2007, Jeremy Henty wrote: > On 2007-07-24, Robert Klemme wrote: > >> If you mean static variables that are visible in a single method >> only, then no, there is no way to do it. > > *cough* > > class Foo > count = 0 > define_method(:foo) { count += 1 } > end > x = Foo.new > 3.times { puts x.foo } > > ==> > 1 > 2 > 3 "Static" is a misleading term, though. It's just a local variable that happens to get wrapped in a closure. In general, I don't think Ruby and the word "static" mix very well :-) Constants are sort of statically scoped, but that's about it. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)