From: Todd Benson Date: 2007-11-07T09:12:29+09:00 Subject: Re: dragons and factorials (keyboard input) On 11/3/07, Thufir wrote: > ps: I'm thinking about class, inheritance and so forth. I'm going to > review another thread where I was asking about the ruby equivalent to > "static class methods" for, specifically, the factorial which I want > ensure cannot be instantiated. I know it's an object, because > everything's an object in Ruby, but have to think about that one. You want to avoid method's being instantiated per object? You can attach the method directly to a class... class C def self.fact puts "factorial goes here" end end C.fact ...or to a module... module M def fact puts "factorial goes here" end end include M foo ...or to a module while preserving namespace... module M def self.fact puts "factorial goes here" end end M::foo For factorial, I like the Rubyish... def fact n (1..n).inject { |fact, i| fact * i } end ...unless there is some performance thing I'm not aware of (or I'm answering the wrong question). Todd