Forum: Ruby on Rails instance_eval and Proc objects

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dan W. (Guest)
on 2006-02-10 17:47
(Received via mailing list)
Hi All,

Got a bit of a Ruby question for you.

If I have a function that makes a proc object like this:

def select(selector, &proc)
  el = Element.new
  el.instance_eval proc
end

select("#thing") do
   hide
end

Wat I want to do is evaluate the Proc in the context of el but this
doesn't work because instance_eval accepts a string or a block and not
a Proc object.  I sense Im barking up the wrong tree here entirely but
Im pretty new to this Ruby game so forgive me.

Any suggestions?

Cheers,

Dan
Dan W. (Guest)
on 2006-02-10 19:10
(Received via mailing list)
It's okay, I worked it out myself:

el.instance_eval &proc

Just like with starred method arguments...

On 2/10/06, Dan W. <removed_email_address@domain.invalid> wrote:
>
>
> Cheers,
>
> Dan
>


--
Dan W.
http://www.danwebb.net
This topic is locked and can not be replied to.