Keith Devens .com |
Sunday, October 12, 2008 | ![]() |
| But goodness alone is never enough. A hard cold wisdom is required, too, for goodness to accomplish good. Goodness without... – Robert Heinlein | ||
|
| ← WHEDONesque: Firefly theme based song. | Neat comparison of Jython and Rhino, with lots of sample code → |

quackeroo wrote:
quackeroo wrote:
I'm assuming you want a function pointer. In Ruby this is accomplished with the method method and the call method. From the PickAxe 2nd ed., page 543:
def square(n)
n*n
end
meth = self.method(:square)
meth.call(9) -> 81
Not sure how to do this in Groovy.
Keith (http://keithdevens.com/) wrote:
quackeroo, thanks, that might be it. What I really want to know how to do is something like:
def foo()
print "whatever"
end
bar(&foo)
Where bar would normally expect a block or a Proc object. Does this make sense?
quackeroo wrote:
If bar's definition uses the & for the last parameter, then that parameter will take a block and turn it into a Proc object:
def foo()
print "whatever"
end
def bar(&block)
block.call()
end
Since you need to pass a block to bar, I suppose you could pass a block with foo in it like so:
bar { foo }
# which should give the same as
bar { print "whatever" }
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):
Generated in about 0.169s.
(Used 8 db queries)

Can you provide pseudo code for clarification? Not sure what you are wanting.