1

I'm trying to figure out how to add constructor parameters to my JRuby Script. I have had it working before with the following code.

class Man < NpcCombat
    def attackScripts attacker, victim
        return [BasicAttack.meleeAttack(attacker, victim,AttackStyle::Mode::MELEE_ACCURATE, 2, Weapon::FISTS)]
    end
end

However the Java Class "NpcCombat" now has a integer parameter, such as NpcCombat(int). I'm trying to figure out how to change this in my ruby script, but it's not working.

1 Answer 1

1

I've never used jruby, but based on Ruby I imagine adding an initialize block that calls the super constructor should work:

class Man < NpcCombat
  def initialize(num)
    super(num)
  end 

  ...

end
Sign up to request clarification or add additional context in comments.

1 Comment

I've used JRuby a lot and can confirm this (very clear) Rubyist approach is 100% correct :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.