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.
0727907ae68db2e8ebc1ea1b01f00d69?d=identicon&s=25 Dan Webb (Guest)
on 2006-02-10 16: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
0727907ae68db2e8ebc1ea1b01f00d69?d=identicon&s=25 Dan Webb (Guest)
on 2006-02-10 18: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 Webb <dan@danwebb.net> wrote:
>
>
> Cheers,
>
> Dan
>


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