Christopher Dicely
4/4/2009 4:08:00 PM
On Sat, Apr 4, 2009 at 8:38 AM, Tomas Na <krazz17@hotmail.com> wrote:
> I am very new to ruby and am trying to create a form using fxRuby. There
> will be a lot of forms so instead of putting them all in one file in
> their own classes I am trying to make them all separate files, placing
> them in the /Forms directory from where the main app is.
>
> The trouble I am having is that when I make, for example "LoginForm.rb"
> and then require it in my main code, I get the error:
>
> test.rb:10:in `initialize': wrong number of arguments (1 for 0)
> (ArgumentError
> )
> from test.rb:10:in `new'
> from test.rb:10
>
> However if I copy and paste the code from LoginForm.rb to test.rb then
> everything runs with no problems. Like so:
>
>
> #require 'Forms/LoginForm.rb'
>
> require 'fox16'
> include Fox
>
> #-- Login Form
> class LoginForm < FXMainWindow
> def initialize(anApp)
> # Initialize base class first
> super(anApp, "testapp", :opts => DECOR_ALL, :width => 400, :height
> => 300)
>
> # Place the list in a sunken frame
> sunkenFrame = FXVerticalFrame.new(self,
> LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding =>
> 0)
>
> end
>
> def create
> super
> show(PLACEMENT_SCREEN)
> end
> end
> #-- End Login Form
>
> xaApp = FXApp.new("testapp", "FXRuby")
> LoginForm.new(xaApp)
> xaApp.create
> xaApp.run
>
>
> The above code works, but if I move the code between the Login Form
> quotes to Forms/LoginForm.rb and uncomment the top require, then I get
> the error that I posted above. I dont understand what the difference
> would be. Can anyone help me out?
I can't reproduce the problem you are having. If I do what you
describe as causing the error (LoginForm code in separate file), with
the requires you list, I get a different error:
/Forms/LoginForm.rb:1: uninitialized constant FXMainWindow (NameError)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from app.rb:1
If I move the first require after the require 'fox16'; include Fox;
pair, it works, even with the LoginForm code in a separate file.