[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Another quicky, sorry.

Skotty

11/9/2006 8:36:00 AM

Ok, I'm doing the examples from
http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_04/cla...

Exactly as it's written on the page.
The first part returns fine, and then I start the second part with the
"sandy_addr = Address.new" and it gives me this.
irb(main):181:0> sandy_addr = Address.new
ArgumentError: wrong number of arguments (0 for 1)
from (irb):181:in `initialize'
from (irb):181
from :0
irb(main):182:0>

Anybody?

--
skt

shyguyfrenzy@gmail.com
"I sing a song, falling upon deaf ears; unsung."


6 Answers

Peter Szinek

11/9/2006 8:55:00 AM

0

skt wrote:
> Ok, I'm doing the examples from
> http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_04/cla...
>
> Exactly as it's written on the page.
> The first part returns fine, and then I start the second part with the
> "sandy_addr = Address.new" and it gives me this.
> irb(main):181:0> sandy_addr = Address.new
> ArgumentError: wrong number of arguments (0 for 1)
> from (irb):181:in `initialize'
> from (irb):181
> from :0
> irb(main):182:0>
>
> Anybody?

I guess the problem could be here: (in Person.initialize)

@address = Address.new

since the initialize() of Address needs 1 param (and not 0):

class Address
def initialize(street)
@street = street
end
end

i.e. the wrong line should read

@address = Address.new('Calle Bolívar, Buenos Aires')

HTH,
Peter

__
http://wwww.rubyra...

Skotty

11/9/2006 8:58:00 AM

0

I'm using irb to get a feel for it yah, I'm probably going to have start
committing to using a text editor (i want textmate so bad, but don't
have a mac).

Anyways I figured out what the problem was...
address = addres.new
is a typo on the page, once I added the second s, i've actually made it
to the end of the example.

I'm using linux btw.
I'd prefer to use this on my windows, (dualboot) so i don't have chmod
everything but limited time and space.

Anyways, wow I thought I was the only one up! :D
skt


Vihan Pandey wrote:
> Hello,
>
>> Ok, I'm doing the examples from
>> http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_04/cla...
>>
>> Exactly as it's written on the page.
>
>
> i've tried most of the examples and to the best of my knowledge, all
> of them
> work just fine.
>
> The first part returns fine, and then I start the second part with the
>> "sandy_addr = Address.new" and it gives me this.
>> irb(main):181:0> sandy_addr = Address.new
>> ArgumentError: wrong number of arguments (0 for 1)
>> from (irb):181:in `initialize'
>> from (irb):181
>> from :0
>> irb(main):182:0>
>
>
> Do you do all your programs on an irb shell ? Its cool for small
> stuff, but
> if your programs are ``pretty big" the chance of commiting a typo on the
> shell and overlooking it is pretty large.
>
> Try pasting the entire thing onto a .rb file and then running ruby on it.
>
> Also, out of pure curiosity(and nothing else), which operating system are
> you using.
>
> Regards,
>
> - vihan
>


--
skt

shyguyfrenzy@gmail.com
"I sing a song, falling upon deaf ears; unsung."


Peter Szinek

11/9/2006 8:59:00 AM

0

skt wrote:
> Ok, I'm doing the examples from
> http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_04/cla...
>
> Exactly as it's written on the page.
> The first part returns fine, and then I start the second part with the
> "sandy_addr = Address.new" and it gives me this.
> irb(main):181:0> sandy_addr = Address.new
> ArgumentError: wrong number of arguments (0 for 1)
> from (irb):181:in `initialize'
> from (irb):181
> from :0
> irb(main):182:0>
>
> Anybody?

Ah, OK, i scrolled down and there is the correct definition of Address
you should use:

class Address
attr_accessor :street, :city, :state, :zip
def initialize
@street = @city = @state = @zip = ""
end
end

so you probably (like me) used a different implementation of Address,
where the constructor takes a parameter.

Replace your implementation of Address with the above one, and
everything should work.

Cheers,
Peter

__
http://www.rubyra...

Skotty

11/9/2006 8:59:00 AM

0

Peter Szinek wrote:
> skt wrote:
>
>> Ok, I'm doing the examples from
>> http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_04/cla...
>>
>> Exactly as it's written on the page.
>> The first part returns fine, and then I start the second part with the
>> "sandy_addr = Address.new" and it gives me this.
>> irb(main):181:0> sandy_addr = Address.new
>> ArgumentError: wrong number of arguments (0 for 1)
>> from (irb):181:in `initialize'
>> from (irb):181
>> from :0
>> irb(main):182:0>
>>
>> Anybody?
>>
>
> I guess the problem could be here: (in Person.initialize)
>
> @address = Address.new
>
> since the initialize() of Address needs 1 param (and not 0):
>
> class Address
> def initialize(street)
> @street = street
> end
> end
>
> i.e. the wrong line should read
>
> @address = Address.new('Calle Bolívar, Buenos Aires')
>
> HTH,
> Peter
>
> __
> http://wwww.rubyra...
>
>
>
Also, there's a typo on the page that I was completely missing.
Thanks!

--
skt

shyguyfrenzy@gmail.com
"I sing a song, falling upon deaf ears; unsung."


Peter Szinek

11/9/2006 9:17:00 AM

0

> i guess all of us are in different time zones :-)
Heh, 10:15 AM here (Europe)

Cheers,
Peter

__
http://www.rubyra...

Luke Graham

11/9/2006 11:56:00 AM

0

On 11/9/06, skt <shyguyfrenzy@gmail.com> wrote:
> I'm using linux btw.
> I'd prefer to use this on my windows, (dualboot) so i don't have chmod
> everything but limited time and space.

If you find you are always doing chmod +x on files with
#!/usr/bin/ruby in the first line, you can always run them with 'ruby
<filename>'. That doesn't require making the file executable, since
it's treated as a datafile by the ruby exec. If for some reason your
new files aren't rw, you probably need to set your umask in your shell
startup script (~/.bashrc or similar).

There are lots of good text editors out there, I'd recommend vim/emacs
but then you'd have two problems ;) nano is probably the way to go for
instant gratification.