Meditations on a Class Method
I keep a file of code I like. When looking for inspiration, I read through the file. It’s short; I often re-write the samples to be nothing but the minimally inspiring thought. Here is the first snippet: def self.run(user) new(user).run end Think on it for yourself before I explain what it means to me. I’d like to hear what it means to you — leave a long comment here before you keep reading. To me, it’s a reminder of how to write a beautiful class method: instantiate the class then call a method on the instance. Look at it from the perspective of the person calling the class method. When you call a class method you want one of two things: either you want to construct an instance of the class itself (.new , or perhaps .new_from_file , .new_for_widescreen , and .new_from_json ), or you want convenience. Think of the class methods you’ve seen, or have written. If they are not...