From: Christoph Date: 2002-09-07T11:20:51+09:00 Subject: Re: Ruby aesthetics "Reimer Behrends" wrote in .... > The problem with nested definitions is that you have identified > an abstraction (the nested defs) that cannot possibly be reused > or varied, since they are hidden within that function. Yes, our neurons seem to work on the wave-length ... to make my point this was my solution to this problem sqrt = Class.new do def self.[](x) new(x).iter(1.0,2.0) end private_class_method :new def initialize(x) @x = x end def good_enough(g1,g2) ((g1 - g2).abs / g2) < .001 end def improve(guess) (guess + @x / guess) /2.0 end def iter(g1,g2) good_enough(g1,g2) ? g2 : iter(g2, improve(g2)) end end p sqrt[4.1] # ... Rather then writing a couple of interconnected methods or procs I find it often preferable to write a (or several) specialized ``method'' class(es) or module(s). /Christoph