From: Robert Klemme Date: 2011-12-21T23:19:17+09:00 Subject: Re: Accessing class instance variables from an instance? On Wed, Dec 21, 2011 at 3:08 PM, Josh Cheek wrote: > Yeah, sorry, it was late. The need I actually come across isn't state > based, but functionality based. For example, HTTParty's get method. From > outside it's nice to be able to say `HTTParty.get(...)` but from inside > they don't want to have to say `self.class.get(...)` so that is an example You can also say HTTParty.get(...) inside instance methods. > of a class level method that should be available to instances without > having to go find the class. I find that need occasionally. Or sometimes > I'm looking at some method and realizing it really could be a class method, > and that no one can use it without instantiating, but it's pretty obnoxious > to have to instantiate a class just to call some method that doesn't depend > on instances. Well, then make it a class method. That has the added advantage that you make the call explicit in instance methods which use it and it is immediately clear that this method does not manipulate instance state. I think this make-a-class-method-be-callable-as-instance-method looks convenient on first sight but on second sight it may just be obfuscation. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/