R
Robert Klemme
Hi,
here's what I'd like to do in a silly example:
S = Struct.new :foo, :bar
init = lambda do |a, b|
self.foo = b
self.bar = a + 10
end
s = S.new # or create an instance otherwise
# now comes the fun part which does not work
s.instance_eval(1, 2, &init)
=> #<struct S foo=2, bar=11>
In other words: I like to define a block as an initializer which I can
store away somewhere and invoke that initializer later on in the
context of "self" and pass arguments at the same time. Any ideas how
I can accomplish this elegantly?
Kind regards
robert
here's what I'd like to do in a silly example:
S = Struct.new :foo, :bar
init = lambda do |a, b|
self.foo = b
self.bar = a + 10
end
s = S.new # or create an instance otherwise
# now comes the fun part which does not work
s.instance_eval(1, 2, &init)
=> #<struct S foo=2, bar=11>
In other words: I like to define a block as an initializer which I can
store away somewhere and invoke that initializer later on in the
context of "self" and pass arguments at the same time. Any ideas how
I can accomplish this elegantly?
Kind regards
robert