On Jul 11, 2006, at 2:45 PM, Daniel Schierbeck wrote:

> Daniel Schierbeck wrote:
>> John wrote:
>>> def describe code
>>>   # takes a string to be eval'ed and prints it along
>>  >   # with showing the return value
>>>   sep = ' => '
>>>   begin
>>>     result = eval(code)
>>>     puts code + sep + result.inspect
>>>     return result
>>>   rescue Exception => e
>>>     puts code + sep + e.to_s
>>>     return nil
>>>   end
>>> end
>> Hi John,
>> You can write than method even more terse:
>>   def describe code
>>     sep = ' => '
>>     result = eval(code)
>>     puts code + sep + result.inspect
>>     return result
>>   rescue Exception => e
>>     puts code + sep + e.to_s
>>     # puts already returns nil
>>   end
>
> or perhaps even
>
>   def describe code
>     out = eval(code).inspect
>   rescue Exception => e
>     out = e.to_s; nil
>   ensure
>     puts code + " => " + out
>   end
>
>
> Cheers,
> Daniel
>

def describe code
   require 'xmp'
   xmp code
end

I cheated though