From: "Jesús Gabriel y Galán" Date: 2010-03-03T01:15:27+09:00 Subject: Re: Compute value inside define_method On Tue, Mar 2, 2010 at 5:00 PM, Karl wrote: > I know there is a 'trick' for forcing a value to compute, but I can't > seem to remember or find it. The following routine needs to computer > the value of 'register += 1' and not insert it literally. > > into.class_eval do >              define_method "#{dow}_#{tod}_time" do >                @registers.get_value( "#{register += 1}".to_i ) >              end >    ...snip... > end > > You can see my attempt above, but it doesn't work. Neither does > 'eval("register += 1")' > > What's the trick? or should I approach the problem from a different > angle? What is register in your code above? Because this should work: irb(main):005:0> register = 0 => 0 irb(main):006:0> "#{register += 1}".to_i => 1 irb(main):008:0> register => 1 irb(main):009:0> "#{register += 1}".to_i => 2 On the other hand, if register is already and int and the get_value method receives an int, why not just: @registers.get_value(register += 1) ? Jesus.