From: Michael Campbell Date: 2003-07-17T23:57:24+09:00 Subject: Re: What's the point? > I've known for some time that methods can be defined inside > methods, but I am still wondering what's the point. > > def fred > def x > puts "x" > end > x > end > > fred > x > > produces > x > x > > Why would any sane person do such a thing? :) I can only remember ever seeing this in Pascal (not that I have a wide language experience base). I can imagine the use for such a construct is similar to "private" methods in a class (in a Java context). You want abstract some procedure or algorithm, but limit its visibility. In the above case, 'x' is only known to 'fred'. If fred was doing a lot of repetitious stuff that wasn't relevant outside fred, it might make sense to abstract the repetitious/common stuff into 'x'. I remember wishing for this sort of thing in C, where I didn't want to clutter the 'global namespace' with my utility functions that were only relevant within another function. Maybe that was poor design on my part.