From: Gennady Bystritsky Date: 2009-04-27T13:09:55+09:00 Subject: Re: JRuby constructor issue or just me? In Ruby, "super()" is different from just "super". The former will invoke a superclass' constructor with no parameters, while the latter will call it with the same number of parameters as was in "new" call. Gennady. > -----Original Message----- > From: Andrew S. Townley [mailto:ast@atownley.org] > Sent: Sunday, April 26, 2009 2:50 PM > To: ruby-talk ML > Subject: JRuby constructor issue or just me? > > Hi, > > I can't figure out why this doesn't work. I need to do this because > I'm > initializing the button elements separately within the constructor, but > I want to ensure that the button is actually created first. I do this > all the time with GTK+ & Ruby/GNOME2 on MRI, but it doesn't seem to > want > to go with JRuby. > > Is this problem something to do with the overloaded JButton > constructors? How can I force a particular one to be called? I've > read > several Google results, but since I'm trying to call the JButton() > constructor with no arguments, I can't figure out what to do. > > Any help would be appreciated. > > Cheers, > > ast > > $ cat $HOME/jbutton.rb > require 'java' > > include_class 'javax.swing.JButton' > > class Foo < JButton > def initialize(count) > super() > self.text = "Foo" > @count = count > end > end > > foo = Foo.new > > $ cat $HOME/output.txt > nene$ c:/devel/src/jruby/bin/jruby -v > jruby 1.3.0 (ruby 1.8.6p287) (2009-04-26 r6586) (Java HotSpot(TM) > Client VM 1.6.0_13) [x86-java] > nene$ c:/devel/src/jruby/bin/jruby jbutton.rb > jbutton.rb:13: wrong # of arguments(0 for 1) (ArgumentError) > > The above example is contrived to produce a suitable testcase, but > based > on the actual code that I'm trying to run. > -- > Andrew S. Townley > http://atownley.org >