extending instance and accessing scope

S

Simon Strandgaard

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 ?
 

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

Similar Threads


Members online

Forum statistics

Threads
474,139
Messages
2,570,807
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top