I am working on a reporting library (perhaps a gem someday). It’s
coming along pretty well thus far, though I could use some collective
intelligence on something.
I would like ActionView::Base (particularly the helpers to be
available within a lambda. The point of this is to define
transformations on columns (0…n) within an instance of the class to
output within an erb template.
For reference, both class A and B below produce the correct result,
but class C is what I’m trying to do.
class A < ActionView::Base
def run
content_tag(‘a’,‘b’)
end
end
class B < ActionView::Base
def run
l = lambda { content_tag(‘a’,‘b’) }
l.call
end
end
class C < ActionView::Base
attr_accessor :l
def run
l.call
end
end
a = A.new
=> #<A:0xb35c9a00 @controller=nil, @assigns_added=nil, @assigns={},
@view_paths=[], @logger=nil>
a.run
=> “b”
b = B.new
=> #<B:0xb35c60f8 @controller=nil, @assigns_added=nil, @assigns={},
@view_paths=[], @logger=nil>
b.run
=> “b”
c = C.new
=> #<C:0xb35c37b8 @controller=nil, @assigns_added=nil, @assigns={},
@view_paths=[], @logger=nil>
c.l = lambda { content_tag(‘a’,‘b’) }
=> #Proc:0xb35bf938@:26(irb)
c.run
NoMethodError: undefined method content_tag' for #<Object:0xb7d249a4> from (irb):26 from (irb):18:in
call’
from (irb):18:in `run’
from (irb):27
Any thoughts?