[LRUG] Getting rid of 'proc'
Paolo Dona
paolo.dona at seesaw.it
Wed Apr 18 03:06:26 PDT 2007
Hi Paul, your sample seems good, but what I'm trying to do with tabnav is a
little bit more complicated.
You're able to define the block do p @foo end because @foo is an instance
variable of your class A (that could correspond to the tabnav model) but
inside the tabnav I should reference something that exists only in the
views's context, not the model.. imagine to evaluate a @foo that's inside
another class..
let's see..
class MyModel
add_tab do
named {params[:name]}
end
end
the params method is raising a syntax error here... Maybe I'm missing
something but I couldn't make your sample work if the @foo is in antother
class...
please highlight me :-)
On 4/17/07, Paul Battley <pbattley at gmail.com> wrote:
>
> Following on from last night's discussion about the use of 'proc' in
> Paolo's TabNav plugin, here's a brief demonstration of how to evaluate
> the block in the right context without needing 'proc' at all:
>
> ---
>
> #!/usr/bin/env ruby
>
> class A
> def initialize
> @foo = 42
> end
>
> def define(&blk)
> @fn = blk
> end
>
> def evaluate
> instance_eval(&@fn)
> end
> end
>
> a = A.new
> a.define do
> p @foo
> end
> a.evaluate # => 42
>
> ---
>
> Paul.
> _______________________________________________
> chat mailing list
> chat at lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
--
Paolo Dona'
SeeSaw | Another point of view
http://www.seesaw.it
paolo.dona at seesaw.it
personal http://paolodona.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20070418/2d765713/attachment-0003.html>
More information about the Chat
mailing list