[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

extending instance and accessing scope

Melanie Fielder

11/18/2003 9:58:00 AM

Often I need to pass variables from that scope in which I
extend an instance.. I wonder if it can be done simpler?


tree = TreeBuilder.new
node_rep = tree.lookup(3)

class << value
attr_accessor :future_input # is this necessary?
def test
@input = @future_input # is this necessary?
super
end
end

value.future_input = node_rep # is this necessary?
value.test
assert_equal(node_rep, value.output)


As you can see there is 3 lines which is dealing with passing a variable
from parent scope into the instance. I find this cumbersome.
Can it be done simpler ?

--
Simon Strandgaard