S
Simon Strandgaard
How do you guys convert yield to block ?
I were hoping to that #mode2 could get same behavier as #mode,
however self is out of control.
server> ruby a.rb
#<ModeInfo:0x8123634 @tabsize=4>
a.rb:18: undefined method `tabsize' for main:Object (NoMethodError)
from a.rb:17:in `mode2'
from a.rb:11:in `instance_eval'
from a.rb:7:in `instance_eval'
from a.rb:7:in `mode'
from a.rb:12:in `mode2'
from a.rb:17
server> expand -t2 a.rb
class ModeInfo
def initialize; @tabsize = 8 end
def tabsize(value); @tabsize = value end
end
def mode(&block)
m = ModeInfo.new
m.instance_eval(&block)
p m
end
def mode2
block = lambda{yield} # attempt to convert yield 2 block
mode(&block)
end
mode do
tabsize 4
end
mode2 do
tabsize 5 # BOOM
end
server>
I were hoping to that #mode2 could get same behavier as #mode,
however self is out of control.
server> ruby a.rb
#<ModeInfo:0x8123634 @tabsize=4>
a.rb:18: undefined method `tabsize' for main:Object (NoMethodError)
from a.rb:17:in `mode2'
from a.rb:11:in `instance_eval'
from a.rb:7:in `instance_eval'
from a.rb:7:in `mode'
from a.rb:12:in `mode2'
from a.rb:17
server> expand -t2 a.rb
class ModeInfo
def initialize; @tabsize = 8 end
def tabsize(value); @tabsize = value end
end
def mode(&block)
m = ModeInfo.new
m.instance_eval(&block)
p m
end
def mode2
block = lambda{yield} # attempt to convert yield 2 block
mode(&block)
end
mode do
tabsize 4
end
mode2 do
tabsize 5 # BOOM
end
server>