From: Gary Wright Date: 2009-07-17T03:30:42+09:00 Subject: Re: Interpolation question with each do block On Jul 16, 2009, at 1:50 PM, Älphä Blüë wrote: > Hi all, > > I have a quick interpolation question.. > > def calculate_tsos(model, datavar) > var = model.find(:all) > var.each do |rows| > puts "#{model} (Team = #{rows.team.name} | #{datavar} = > #{rows.datavar}" > end > end > > The only thing that doesn't work is the datavar within interpolation > in > the puts statement. How do I make it so that my datavar value is > passed > to datavar in the puts statement so that it would be similar to: > > datavar = ydspgm > > rows.datavar should be equal to rows.ydspgm but it's not. I'll get > an > undefined method datavar. I'm not sure how I can pass the name of > that > variable to that interpolation piece of code. I'm not 100% sure but I believe, the problem is that you want to call the method named by the *contents* of datavar but instead you are calling the method named 'datavar', which of course isn't defined. Try this instead: > puts "#{model} (Team = #{rows.team.name} | #{datavar} = > #{rows.__send__(datavar)}" Gary Wright