dblack / wobblini.net wrote: > > class Foo > > def bar(*args, &block) > > if block_given? > > class << block > > @@return = {} > > lambd.define_method(:method_missing, (m, *args, &b) > > return @@return.merge!({ m.to_sym => args }) > > end Whoops, that wasn't actually my code :-/ Just to restore a little credibility it should have read; def method_missing(m, *args, &block) return @@return << { m.to_sym => args } end > > end > > attributes = lambd.instance_eval(&block) > > end > > p attributes > > end > > end Which works fine ( I do want to reset @@return each time). > > @@return is going to be a new variable each time you call bar with a > block, so it won't accumulate results from multiple calls (which I > think is what you want to do). > > See if this either does what you want or suggests some possibilities: > > class Foo > > def bar(*args, &block) > method_calls = {} > if block > (class << block; self; end).class_eval do > define_method(:method_missing) do |m,*args| > method_calls.merge!({ m.to_sym => args }) > end > end > attributes = block.instance_eval(&block) > p attributes > end > end > end But this is nicer because the class variable was a kludge because I couldn't figure out how to keep a variable from outside the block in scope. Thanks, James