2007/7/24, Jeremy Henty <onepoint / starurchin.org>: > On 2007-07-24, dblack / wobblini.net <dblack / wobblini.net> wrote: > > > > On Tue, 24 Jul 2007, Jeremy Henty wrote: > > > >> On 2007-07-24, Robert Klemme <shortcutter / googlemail.com> wrote: > >> > >>> If you mean static variables that are visible in a single method > >>> only, then no, there is no way to do it. > >> > >> class Foo > >> count = 0 > >> define_method(:foo) { count += 1 } > >> end > > > > "Static" is a misleading term, though. It's just a local variable > > that happens to get wrapped in a closure. > > True, but it is still "visible in a single method only", which AIUI > Robert Klemme claimed was undoable. Even though Ruby doesn't have > truely static variables, it can create something that behaves very > like (a common use case of) them. That's all I'm claiming. Well, in Ruby there is usually a workaround. But there is no real built in static method variables feature. So we're both correct in a way. :-) Also, I did not want to encourage people to use this pattern because I believe it's not good. Here's why: if you have a design complex enough make separation of your instance state by method necessary then you should break up functionality into more classes to keep it manageable. Kind regards robert