def foo(&block)
def block.bar
puts "in bar"
end
block.call
end
foo do
bar
end
--
You received this message because you are subscribed to the Google Groups "pdxruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdxruby+u...@googlegroups.com.
To post to this group, send email to pdx...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdxruby/4312d753-cf81-4f1f-b3fc-0934239472de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Apr 20, 2016, at 12:25 PM, William Hertling <william....@gmail.com> wrote:
Ah, that approach appeared to work at first glance, but what I didn't realize is that by overriding self, it has basically killed inheritance, so that my block can't call other methods it is dependent on.Is there any other way to achieve it that would preserve inheritance?
--
You received this message because you are subscribed to the Google Groups "pdxruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdxruby+u...@googlegroups.com.
To post to this group, send email to pdx...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdxruby/aeccf4ea-15ad-4ba2-837f-efa29beae8ef%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "pdxruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdxruby+u...@googlegroups.com.
To post to this group, send email to pdx...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdxruby/4312d753-cf81-4f1f-b3fc-0934239472de%40googlegroups.com.
Ah, that approach appeared to work at first glance, but what I didn't realize is that by overriding self, it has basically killed inheritance, so that my block can't call other methods it is dependent on.Is there any other way to achieve it that would preserve inheritance?
--
You received this message because you are subscribed to the Google Groups "pdxruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdxruby+u...@googlegroups.com.
To post to this group, send email to pdx...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdxruby/aeccf4ea-15ad-4ba2-837f-efa29beae8ef%40googlegroups.com.
A binding can have only one implicit receiver ("self"). If your code that is evaluating the block has access to all the objects that have the methods you want, you could potentially create a new object that serves as a facade for that assemblage of objects. However, this would be a _really bad idea_.I strongly recommend not messing with the binding of blocks. If you want to provide a context on which the block can call methods, pass it as an explicit argument:def foo(&block)
block.call(self)
endfoo do |context|
context.barend
Ah, that approach appeared to work at first glance, but what I didn't realize is that by overriding self, it has basically killed inheritance, so that my block can't call other methods it is dependent on.Is there any other way to achieve it that would preserve inheritance?