2009/12/14 Florian Gilcher <flo / andersground.net>: > > On 13 dñÄ. 2009, at 23:46, Ruby Newbee <rubynewbee / gmail.com> wrote: > >> I have two questions, >> >> 1. what's the difference between class method and module method? >> 2. when I say: Dir.pwd, is this a class method or a module method? How >> to know if Dir is a module or a class? > > If you check Class.ancestors, you will find that classes are modules. The > only difference is that classes have methods like #new and #allocate. So,n > your case: it doesn't really matter, but you could check: > > ir.respond_to? :new There is a more direct variant which is also safer (you can make a module respond to :new): irb(main):001:0> Dir.class => Class irb(main):002:0> Enumerable.class => Module irb(main):003:0> > For the methods themselves, there is no difference anyways: they belong to > objects. Whether that is a class, a module or something else make so > difference. That's true - technically. There is still a semantic difference: class objects are always singletons while instances are typically many. This mainly determines what functionality goes into a class method and what into an instance method. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/