Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
Store erb block and alter scope of erb block eval?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Gavin Kistner, post: 4467118"] Works for me: class Foo def set_block( &block ); @meth = block; end def call_block( *args ); @meth.call( *args ); end end f = Foo.new f.set_block { |x,y| p x,y } f.call_block 3,4 #=>3 #=>4 require 'erb' class Foo def rhtml=( str ) @rhtml = ERB.new( str ) end def run1 localvar = 'run1' @rhtml.result( binding ) end def run2 localvar = 'run2' @rhtml.result( binding ) end end f = Foo.new f.rhtml = '<p><%= localvar %></p>' p f.run1 #=> "<p>run1</p>" p f.run2 #=> "<p>run2</p>" [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Store erb block and alter scope of erb block eval?
Top