On Wed, 25 Jun 2003 00:09:31 +0900, Robert Klemme wrote:

> "Luigi Ballabio" <luigi.ballabio / fastwebnet.it> schrieb im Newsbeitrag
> news:pan.2003.06.24.14.18.21.963302 / fastwebnet.it...
>> Hi all,
>> having to design a usable environment for non
>> extremely-computer-literate users, I'd like them to fire
>> up irb with some default options via an alias and write:
>>
>> Foo> foo = 'life'
>> Foo> bar = 'the universe'
>> Foo> baz = 'everything'
>> Foo> calculate
>>      ==> 42
>> Foo>
>>
> 
> If you can guess the variable names you can do:
> 
> b = eval 'x'

Hmm, not if calculate is defined in another module, I think...

> A simple solution to your problem is to use instance variables like this:
> 
> irb(main):001:0> @foo = 'life'
> "life"
> irb(main):002:0> @bar = 'the universe'
> "the universe"
> irb(main):003:0> @baz = 'everything'
> "everything"
> irb(main):004:0>
> irb(main):005:0* instance_variables
> ["@bar", "@foo", "@baz"]
> irb(main):006:0> instance_variables.map{|var| eval var}
> ["the universe", "life", "everything"]
> irb(main):007:0>

I like this one! Again, the eval part won't work if calculate is
defined elsewhere, but I do know the variable names, so I can just
use them...

Thanks,
	Luigi