Newbie wrong # of arguments(4 for 0) question 
Author Message
 Newbie wrong # of arguments(4 for 0) question

It's true that attr_reader gives you the ability to
do:

puts mySong.name

..but it doesn't let you initialize all of these
attributes during construction.

Additionally, if you want to *write* to an attribute,
you need attr_writer (or attr_accessor, which provides
both read and write capability).

So, even if you had writers and readers, you would
still have to call each one separately to initialize
all of the values.  

later,
Chad


Quote:
> Armin,

> Thanks, that does fix my error, but I was sort of
> under the impression
> that attr_reader did that for you in the pick axe
> book I see:

> class Song
>   attr_reader :name, :artist, :duration
> end
> aSong = Song.new("Bicylops", "Fleck", 260)

> but entering this into irb shows me it is incorrect.
>  Thanks for
> solution!

> Erik

> > -----Original Message-----

> > Sent: Saturday, November 03, 2001 3:35 PM
> > To: ruby-talk ML
> > Subject: [ruby-talk:24292] Re: Newbie wrong # of
> arguments(4 for 0)
> > question

> > Hi,

> >       what about adding  initialize to Revision?
> > --
> > class Revision
> >   attr_reader :revision, :date, :name, :log
> >   def initialize(revision,date,name,log)


> >   end
> > end
> > ---

> > Bye,
> >       Armin


> > > Well I've finally found an excuse to write some
> ruby, and I
> > haven't made it
> > > far before
> > > I've gotten myself stuck.  I remember a joke
> about the
> > arguments error from
> > > Ruby Conf,
> > > but can't remember the punch line :(

> > > I'm sure I am making some simple little mistake,
> but I have no
> > pair so I am
> > > at a loss.
> > > If anyone can offer assistance I would be most
> appreciative.

> > > --

> > > Senior Consultant      Object Mentor, Inc.
> > > http://www.*-*-*.com/

> > > Here is my test:
> > > =========================
> > > require 'revision'
> > > require 'runit/testcase'
> > > require 'runit/assert'
> > > require 'runit/cui/testrunner'

> > > class TestRevision < RUNIT::TestCase

> > >   def setup
> > >     super
> > >   end

> > >   def test_equals
> > >     aRevision = Revision.new("1.4", "2001/10/21
> 02:30:18", "kbeck",
> > > "Enhanced TextRunnerTest to catch missing return
> values.")
> > >     bRevision = Revision.new("1.4", "2001/10/21
> 02:30:18", "kbeck",
> > > "Enhanced TextRunnerTest to catch missing return
> values.")
> > >     assert_equals(aRevision, bRevision)
> > >   end
> > > end

> > > RUNIT::CUI::TestRunner.run(TestRevision.suite)
> > > ==========================

> > > And the file I'm testing:

> > > ==========================
> > > class Revision
> > >   attr_reader :revision, :date, :name, :log
> > > end
> > > ==========================

> > > And of course, the error:

> > > ==========================
> > > $ ruby test_revision.rb

> > > TestRevision#test_equals E.
> > > Time: 0.0
> > > FAILURES!!!
> > > Test Results:
> > >  Run: 1/1(0 asserts) Failures: 0 Errors: 1
> > > Errors: 1
> > > test_revision.rb:13:in
> `initialize'(TestRevision): wrong # of
> > arguments(4
> > > for 0)
> > >  (ArgumentError)
> > >         from test_revision.rb:13:in `new'
> > >         from test_revision.rb:13:in
> `test_equals'
> > >         from test_revision.rb:19
> > > ==========================

> > --
> > Armin.

> > -----------------------------------------------
> > Armin Roehrl, http://www.*-*-*.com/
> > "The best way to predict the future is to invent
> it."
> >                                           --Alan

Kay

__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://www.*-*-*.com/



Thu, 22 Apr 2004 05:51:49 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. wrong output from a variable (newbie question)

2. Simple Newbie Question: What am I doing wrong?

3. Fortran argument passing question (Newbie)

4. default arguments newbie question

5. macro argument verifying (newbie question)

6. Actual Argument & Dummy Argument question

7. Newbie Question (Was: Newbie Question...)

8. What's wrong with my argument type?

9. function arguments: what is wrong with this

10. IVF 10 Bug: Wrong branch returned by SQRT for COMPLEX*16 argument

11. Wrong Arguments on Tcl_ListObjReplace crash system

12. wrong arguments for while during reading a file

 

 
Powered by phpBB® Forum Software