From: "John Cusick" <jcusickc / home.com>
Subject: [ruby-talk:8101] Another Nuby question
Date: Wed, 27 Dec 2000 13:40:02 +0900

Hi,

> irb(main):004:0> aSong = Song.new("Bicylops", "Fleck", 260)
> ArgumentError: wrong # of arguments(3 for 0)
> (irb):4:in `initialize'
> (irb):4:in `new'
> (irb):4:in `irb_binding'
> irb(main):005:0> 
> 
> so what key piece of information did I miss in order to make this work?
You must define the "Song#initialize" method.
The Song.new method calls the Song#initialize with three arguments.
So the following code will work fine.

class Song
  def initialize(name, artist, duration)
    @name, @artist, @duration = name, artist, duration
  end
  attr_reader :name, :artist, :duration
end

--
@name, @artist, and @duration are instance variables.
The Module#attr_reader method defines the followings.

class Song
  def name; @name; end
  def artist; @artist; end
  def duration; @duration; end
end  

-- rubikitch