Forum: Ruby simple ruby program not working

D652f548b5f961aac133daf6f30d6f2f?d=identicon&s=25 Nn Bb (conorliv)
on 2014-02-05 02:13
I'm trying to simply add 200 to index, but am getting the error:
"`initialize': undefined method `+' for #<NumNode:0x82537b4 @num=2>
(NoMethodError)"
Any thoughts on how I can fix this?

class StoreNode < UnaryNode
  def initialize(subTree, index)
    super(subTree)
    @theIndex = index + 200
  end

  def evaluate()
    i = @subTree.evaluate()
    $calc.out.write("M[")
    $calc.out.write(@theIndex)
    $calc.out.write("]:= M[sp + 0]\n")
  end
end
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2014-02-05 02:24
(Received via mailing list)
On Tue, Feb 4, 2014 at 5:13 PM, Conor Mr <lists@ruby-forum.com> wrote:
> I'm trying to simply add 200 to index, but am getting the error:
> "`initialize': undefined method `+' for #<NumNode:0x82537b4 @num=2>
> (NoMethodError)"
> Any thoughts on how I can fix this?

Define a "+" method on the "NumNode" class?
D652f548b5f961aac133daf6f30d6f2f?d=identicon&s=25 Nn Bb (conorliv)
on 2014-02-05 02:59
Thank you! Got it working.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.