Using require, cant pass parameter..

T

Tomas Na

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", :eek:pts => 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?
 
C

Christopher Dicely

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", :eek:pts => 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.
 
T

Tomas Na

Ah, my apologies. I had made a typo, my LoginForm.rb was called
LoginFom.rb. Indeed there was also file of the correct spelling with a
class expecting no parameters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top