C
Corey
I'm reading pages 358 & 359 in the pickaxe2 and having a tough time
wrapping my mind around what exactly is going on.
I've got a few simple questions that I'm hoping will help clarify my
confusion.
What's the difference between the two methods below?
def meth1
yield
end
def meth2(&b)
b.call
end
What's the difference between the next two blocks? Does 'next' in any way
make any sort of functional or subtle difference?
blk = meth1 { 99 }
puts blk
blk = meth1 { next 99 }
puts blk
and...
Why does the following cause an exception?
meth { return 99 }
As far as the above goes, I'm really struggling to understand how the
scope and context works.
"A return from a block whose original context is not longer valid raises
an exception ( LocalJumpError )."
In the following:
meth { return 99 }
_Where_/_What_ exactly _is_ the "original context", and how exactly does
it become "no longer valid" with the 'return' statement?
I've got some other questions, but I'm hoping that the above will help
make some things 'click' for me.
Many thanks!
wrapping my mind around what exactly is going on.
I've got a few simple questions that I'm hoping will help clarify my
confusion.
What's the difference between the two methods below?
def meth1
yield
end
def meth2(&b)
b.call
end
What's the difference between the next two blocks? Does 'next' in any way
make any sort of functional or subtle difference?
blk = meth1 { 99 }
puts blk
blk = meth1 { next 99 }
puts blk
and...
Why does the following cause an exception?
meth { return 99 }
As far as the above goes, I'm really struggling to understand how the
scope and context works.
"A return from a block whose original context is not longer valid raises
an exception ( LocalJumpError )."
In the following:
meth { return 99 }
_Where_/_What_ exactly _is_ the "original context", and how exactly does
it become "no longer valid" with the 'return' statement?
I've got some other questions, but I'm hoping that the above will help
make some things 'click' for me.
Many thanks!