From: Ezra Zygmuntowicz Date: 2006-08-08T11:35:44+09:00 Subject: Re: Extracting instance variables from a block? --Apple-Mail-41-603677658 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Aug 7, 2006, at 6:08 PM, Chris Eskow wrote: > Hello fellow Rubyists, > > I am writing a tiny custom web framework, similar in nature to web.py > (http://webpy.org/). However, I'd like someone with better > metaprogramming-foo to help me clean up some syntax a bit. > > Here's a _very_ basic abbreviated version of the framework: > > > So, my question: is there any way to capture the instance variables > set > in the block, and use them for a template binding elsewhere? Or at > least > do something else that gives me my desired results? > > Thanks, > Chris > > -- > Posted via http://www.ruby-forum.com/. > Hey Chris- Cool little class ;) Take a look at this, you should be able to use something like it to do what you want. class Web def page(url, &blk) @url = url instance_eval &blk end end web = Web.new web.page '/hello/(\w+)' do |name| @title = 'Hello' @name = "Ernie" end puts web.inspect => # -Ezra --Apple-Mail-41-603677658--