# Not sure what is wrong. strange error

**URL:** <https://www.ruby-forum.com/t/not-sure-what-is-wrong-strange-error/68830>\
**Category:** Ruby\
**Created:** [September 15, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/not-sure-what-is-wrong-strange-error/68830 "2006-09-15T19:31:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [September 15, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/not-sure-what-is-wrong-strange-error/68830/1 "2006-09-15T19:31:04Z")

</div>

My class declation is like this

class TorontoTraderLoader  
INDEX\_SYMBOL=2  
STOCK\_SYMBOL=1  
@backTestDb=[‘backtestBackTest’, ‘user’,‘pass’]

```
def initialize(backTesting)
	@exchanges=@industries=@sectors=@stocksymbols=''
	@dbcon=DbAccess.new(@backTestDb)
	loadLookup
end
def initialize()
@exchanges=@industries=@sectors=@stocksymbols=''

	loaddbConn
	loadLookup
end

```

…  
I get the following error and it is so odd  
irb(main):001:0\> require ‘TorontoTraderLoader’  
=\> true  
irb(main):002:0\> a=TorontoTraderLoader.new(‘ww’)  
ArgumentError: wrong number of arguments (1 for 0)  
from (irb):2:in `initialize’  
from (irb):2

It does not make any sense. i have a overloaded constructor. i am not  
sure why it does not call teh overloaded constructor

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [September 15, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/not-sure-what-is-wrong-strange-error/68830/2 "2006-09-15T19:35:05Z")

</div>

Hello !

> end  
> sure why it does not call teh overloaded constructor  
> There is no such thing as overloading in Ruby. Your second definition  
> is cancelling the first one. Try to run this with ruby -w, and you’ll  
> get a warning…

Ruby is not C++ 😉 !

```
Vince
```

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [September 15, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/not-sure-what-is-wrong-strange-error/68830/3 "2006-09-15T19:47:06Z")

</div>

On Sat, 16 Sep 2006, Junkone wrote:

> ```
> loadLookup
> 
> ```
> 
> =\> true  
> irb(main):002:0\> a=TorontoTraderLoader.new(‘ww’)  
> ArgumentError: wrong number of arguments (1 for 0)  
> from (irb):2:in `initialize’  
> from (irb):2
> 
> It does not make any sense. i have a overloaded constructor. i am not

No, you redefined it. No overloading in Ruby (because “Duck Typing”)

> sure why it does not call teh overloaded constructor

Maybe

def initialize(backTesting = nil)  
@exchanges=@industries=@sectors=@stocksymbols=’’  
if backTesting.nil?  
@dbcon=DbAccess.new(@backTestDb)  
else  
loaddbConn  
end  
loadLookup  
end

is more the kind of think you want, but in the first method you  
don’t seem to use the param backTesting anyway.

```
    Hugh
```

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [September 15, 2006, 8:19pm UTC](https://www.ruby-forum.com/t/not-sure-what-is-wrong-strange-error/68830/4 "2006-09-15T20:19:08Z")

</div>

On Sat, 16 Sep 2006, Vincent F. wrote:

> > It does not make any sense. i have a overloaded constructor. i am not  
> > sure why it does not call teh overloaded constructor
> 
> There is no such thing as overloading in Ruby. Your second definition  
> is cancelling the first one. Try to run this with ruby -w, and you’ll  
> get a warning…
> 
> Ruby is not C++ 😉 !
> 
> Vince

It’s too bad Ruby does not allow overloaded methods. It makes more  
sense,  
IMHO, in this case to have two constructors, each of which perform two  
different ‘functions’, rather than having if/else/case statements inside  
the constructor with default arguments.

Nate

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [September 15, 2006, 11:47pm UTC](https://www.ruby-forum.com/t/not-sure-what-is-wrong-strange-error/68830/5 "2006-09-15T23:47:29Z")

</div>

hi, see the other posts about overloading, but i’ll try to help with  
your case

On 9/15/06, Junkone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> loadLookup
> end
> def initialize()
> @exchanges=@industries=@sectors=@stocksymbols=''
> 
> loaddbConn
> loadLookup
> end
> 
> ```

It looks like you want to use an optional parameter

try:

def initialize(back\_testing=nil)  
@exchanges = “”  
@industries = “”  
@sectors = “”  
@stock\_symbols = “”  
@dbcon = back\_testing ? DbAccess.new(@back\_test\_db) : load\_db\_con  
load\_lookup  
end

I think this will do what you’d expect it to do

new() will call load\_db\_con, new(true) would be calling your  
back\_test\_db

====

I am a little bit concerned with the way you’ve organized this class,  
but hopefully this will at least show three things.

1. How to use optional parameters

2. ruby\_style instead of javaStyle

3. note that I split up the assignment for your instance variables?  
It is because they were pointing to the same object.

> > a = b = “foo”  
> > =\> “foo”  
> > a.replace “bar”  
> > =\> “bar”  
> > b  
> > =\> “bar”
