From: Paul Lutus Date: 2006-12-05T03:15:09+09:00 Subject: Re: How to use a String obj both in Proc.new and for puts Richard wrote: > Hi All, > > In the appended code I duplicate the text so I can both display it and > define a new Proc. Is there away I can use, say, > > text = '[*1..n].join(", ")' > > in the body of the Proc spec. and thus simply > > puts text? Are you asking how to create a string that can serve for display and also serve as the executable content of a Proc instance? -------------------------------------- #!/usr/bin/ruby -w s = "x = Math.sqrt(2);puts x * x;" p = Proc.new { eval s } puts s p.call() -------------------------------------- Output: x = Math.sqrt(2);puts x * x; 2.0 Or are you asking how to cause the proc object to be executed when you put it in this kind of context: puts proc_object For the second case, you could create a class that redefines to_s: class UntestedExample def to_s return p.call() # something like this end end ute = UntestedExample.new puts ute -- Paul Lutus http://www.arachnoid.com