From: dblack@... Date: 2007-08-16T01:13:50+09:00 Subject: Re: Singleton or full static class Hi -- On Thu, 16 Aug 2007, Frank Meyer wrote: > In other languages I'm using the singleton pattern when I need a > globally accessible object. But in Ruby so much is an object or behaces > like an object (or can be treated as an object) I'm not sure if I should > use the singleton pattern or make all methods to class methods and use > class variables. > What is the best practise in ruby? There's no one answer to that (except I tend to frown on class variables, because they're so unencapsulated and weird :-) You can create a class, or for that matter any other constant, which will be visible from "below": C = Object.new def C.greet puts "hi" end class D def initialize C.greet end end D.new # hi and so on. Or C can be a class or a module. There are lots of different techniques available; I don't think there's one that's always better than all the others. 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)