On Aug 23, 2009, at 15:02 , Martin Emde wrote:

> proc = Proc.new { |hash| puts "#{hash[:bar]}" }
>
>
> proc.call(h)

Call takes an array. I'm trying to do the equivalent of call, but by  
name. So passing a hash instead of an array to something equivalent to  
call.

I was just thinking that if I can convert a proc to an UnboundMethod,  
I can attach it to an object and use method_missing. But I don't see  
such a conversion.

Maybe I should just use Lua... :-)

>
> On Sun, Aug 23, 2009 at 2:56 PM, Guyren G Howe <guy...@gmail.com>  
> wrote:
>
> I want to take a proc, retain its closure, and call it, but rather
> than pass it args in the normal fashion, I want to have it merge a
> hash into its bindings also.
>
> Something like this:
>
> foo = "FOO"
>
> h = {:bar => "BAR"}
>
> p = Proc.new do
>        puts "#{foo}#{bar}"
> end
>
> p.call_with_hash h
>
> #prints FOOBAR
>
> Can't quite see how to do it. Anyone?

Regards,

Guyren G Howe
Relevant Logic LLC

guyren-at-relevantlogic.com ~ http://relevantlogic.com ~ +1 512 784 3178

Ruby/Rails,  REALbasic, PHP programming
PostgreSQL, MySQL database design and consulting
Technical writing and training

Read my book, Real OOP with REALbasic: 
<http://relevantlogic.com/oop-book/about-the-oop-book.php 
 >


--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
sdruby@googlegroups.com
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to