From: Chuck Remes Date: 2011-12-06T03:00:59+09:00 Subject: Re: help with recursive method def'n using eval On Dec 5, 2011, at 4:01 AM, Pete Higgins wrote: > On Sun, Dec 4, 2011 at 9:57 AM, Chuck Remes wrote: > >> On Dec 3, 2011, at 8:49 PM, Intransition wrote: >> >>> On Saturday, December 3, 2011 4:44:58 PM UTC-5, Chuck Remes wrote: >>> I should have waited a few more minutes. After typing this up, I was hit >> by inspiration. Here is my solution. >>> >>> I find writing an issue up often helps me figure out a problem, so it's >> not uncommon to post for some help and then figure it out a few minutes >> later. >>> >>> Maybe a good lesson in this -- write up the post, but give it a few >> minutes before actually sending it. >> >> Quite true. Perhaps my "thinking out loud" in public has been helpful for >> someone else too. >> >> I guess the technical term for this is "rubber ducking." >> >> cr >> >> > If it's not important to output the constructed string, you could do it > like this: > [snip alternative approach] Pete, thanks for figuring out another approach. I prefer building a string and eval'ing it because it's easier (IMHO) to verify that the generated code is correct by examining the string. Using #define_method works quite well too, but when something is wrong with the method definition it's a bit tougher to track down and fix. cr