Forum: Ruby simple ruby program not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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.
This topic is locked and can not be replied to.