[LRUG] Getting rid of 'proc'
Eleanor
eleanor at goth-chic.org
Wed Apr 18 05:12:11 PDT 2007
On 18 Apr 2007, at 11:13, Paul Battley wrote:
> #!/usr/bin/env ruby
>
> class A
> def define(&blk)
> @fn = blk
> end
>
> def evaluate(context)
> context.instance_eval(&@fn)
> end
> end
>
> class B
> def initialize
> @foo = 42
> end
> end
>
> a = A.new
> a.define do
> p @foo
> end
> b = B.new
> a.evaluate(b) # => 42
I may be missing something obvious here, but surely for that to work
the 'define' and 'evalute' methods would have to be implemented in
the class handling the view? I've not explored that aspect of Rails
much so I don't know how easy this would be to implement cleanly, but
compared to the explicit use of a Proc object it seems somewhat less
obvious.
Ellie
Eleanor McHugh
Games With Brains
----
raise ArgumentError unless @reality.responds_to? :reason
More information about the Chat
mailing list