From: Todd Benson Date: 2007-11-07T18:52:56+09:00 Subject: Re: dragons and factorials (keyboard input) On Nov 6, 2007 10:55 PM, Thufir wrote: > > I think that factorial would best be a module, as module's cannot be > instantiated. However, I would also want to prevent factorial from > being extended so that nothing "from" it can be instantiated. The > idea of a factorial "object", or an object which descends from it, > strikes me as ludicrous. Is this un-ruby-ish thinking? No, not really. But keep in mind you can always make a copy of a method on the fly in Ruby (unless $SAFE level alters this behavior; which I'm not sure of)... module M def self.factorial n; (1..n).inject { |f,i| f * i }; end end class C; end c.extend(M) c.fact # will result in error, which is what you want m = Math.method(:factorial) m.call 3 # will result in 6 Math.method(:factorial) == Math.method(:factorial) # will result in true Math.method(:factorial).object_id == Math.method(:factorial).object_id # will result in false on my machine, but that's what I expect > -Thufir Todd