B
Bob Sidebotham
When I execute this code, I get "no block given (LocalJumpError)":
class S
def initialize(&b1)
@b1 = b1
end
def each
@b1.call
end
end
s = S.new {[1,2,3].each {|i| yield i }}.each {|v| puts v}
Changing the implied block/yield combination to an explicit proc object
works, as follows:
class S
def initialize(&b1)
@b1 = b1
end
def each(&b2)
@b1.call(b2)
end
end
s = S.new { |p| [1,2,3].each { |i| p.call(i) }}.each {|v| puts v}
This prints the expected 3 lines.
This is with ruby 1.8.2 (2004-09-10) [i686-linux]
It's quite possible that I don't understand how this is supposed to work
. Any hints would be appreciated.
Thanks,
Bob Sidebotham
class S
def initialize(&b1)
@b1 = b1
end
def each
@b1.call
end
end
s = S.new {[1,2,3].each {|i| yield i }}.each {|v| puts v}
Changing the implied block/yield combination to an explicit proc object
works, as follows:
class S
def initialize(&b1)
@b1 = b1
end
def each(&b2)
@b1.call(b2)
end
end
s = S.new { |p| [1,2,3].each { |i| p.call(i) }}.each {|v| puts v}
This prints the expected 3 lines.
This is with ruby 1.8.2 (2004-09-10) [i686-linux]
It's quite possible that I don't understand how this is supposed to work
. Any hints would be appreciated.
Thanks,
Bob Sidebotham