# Using require, cant pass parameter

**URL:** <https://www.ruby-forum.com/t/using-require-cant-pass-parameter/164716>\
**Category:** Ruby\
**Created:** [April 4, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/using-require-cant-pass-parameter/164716 "2009-04-04T17:39:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc79bd/32.png) [@tomast](https://www.ruby-forum.com/u/tomast)\
**Post date:** [April 4, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/using-require-cant-pass-parameter/164716/1 "2009-04-04T17:39:32Z")

</div>

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 =>

```

1. 

```
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?

---

<div class="post-metadata">

**Author:** ![tomast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc79bd/32.png) [@tomast](https://www.ruby-forum.com/u/tomast)\
**Post date:** [April 4, 2009, 6:09pm UTC](https://www.ruby-forum.com/t/using-require-cant-pass-parameter/164716/2 "2009-04-04T18:09:57Z")

</div>

On Sat, Apr 4, 2009 at 8:38 AM, Tomas Na [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> )  
> include Fox  
> LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y|FRAME\_SUNKEN|FRAME\_THICK, :padding =\>
> 
> 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.

---

<div class="post-metadata">

**Author:** ![tomast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc79bd/32.png) [@tomast](https://www.ruby-forum.com/u/tomast)\
**Post date:** [April 4, 2009, 7:34pm UTC](https://www.ruby-forum.com/t/using-require-cant-pass-parameter/164716/3 "2009-04-04T19:34:40Z")

</div>

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.
