T
Trans
Mental block. Is there a reasonable way to do this?
def dothis ; puts "NO!" ; end
module M
class << self
def dothis
puts "THIS" + @number.to_s
end
def wrap( n, &yld )
old = @number
@number = n
yld.call
@number = old
end
end
end
M.wrap( 10 ) do
dothis
end
This produces "NO!". How do I get it to execute the block in the
context of M, so that it produces "THIS10" (w/o having to out
M.dothis).
Thanks,
T.
def dothis ; puts "NO!" ; end
module M
class << self
def dothis
puts "THIS" + @number.to_s
end
def wrap( n, &yld )
old = @number
@number = n
yld.call
@number = old
end
end
end
M.wrap( 10 ) do
dothis
end
This produces "NO!". How do I get it to execute the block in the
context of M, so that it produces "THIS10" (w/o having to out
M.dothis).
Thanks,
T.