Malleable Instance Vars

G

gwtmp01

Are we ready for

@x = 1

a = "x"

@{a} #=> 1

Not me, but how about:

container@[index]

as sugar for:

self.container@(index)

and

container@[index] = val

as sugar for:

self.container@=(index, val)

As a degenerative case you could omit the 'container':

def @[](index); end
def @[]=(index); end


Gary Wright
 
E

Eric Hodel

Are we ready for

@x = 1

a = "x"

@{a} #=> 1

PHP-style "variable variables" just lead to code that is too clever
for its own good. Using a Hash is a much more readable solution.
 
T

Trans

Eric said:
PHP-style "variable variables" just lead to code that is too clever
for its own good. Using a Hash is a much more readable solution.

Perhaps so. And I am presently working on such code. BUt to be honest,
I haven't found a more reasonble way to handle it. As it stands I have
to do instance_variable_get/set or eval the whoe method def.

T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,579
Latest member
CharaS3188

Latest Threads

Top