--nextPart3734105.V7IelrB8Tr
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

quoth the James Britt:
> darren kirby wrote:
> > Hello all,
> >
> > So you can see I need to explicitly call each attribute before my array
> > gets the value. How can I change this so the array is populated
> > automatically when called?
>
> Add code to to_a to populate the instance variables if they are not et
> assigned, or have the initializer assign the instance variables when an
> object is created.

Ok, so I changed the code so the assignments are in initialize(). Now I am=
=20
getting some broken behavior. First of all, most of the tags are getting se=
t=20
by the super class which is only supposed to happen if the tag is 'comment':

irb> x =3D OggMetaTags.new('/home/music/e/elliottSmith-shootingStar.ogg')
=3D> #<OggMetaTags etc etc
irb> x.to_a
=3D> ["/home/music/e/elliottSmith-shootingStar",=20
"/home/music/e/elliottSmith-shootingStar", "unknown", "unknown", "unknown",=
=20
"unknown", "12"]

So here the only tag set correctly is the tracknumber "12". The rest were s=
et=20
by the super class except for 'comment' which is supposed to be 'Starbellie=
d=20
using sneetchalizer' but is instead 'unknown'?! I am completely lost as to=
=20
what is going on here.

I suppose I better list the super class as well:

class MetaTags
  attr_reader :title, :artist, :album, :genre, :year, :comment, :tracknum
  def initialize(filename)
    @filename =3D filename
    @title    =3D @filename[0..-5]
    @artist   =3D @title
    @album    =3D 'unknown'
    @genre    =3D 'unknown'
    @year     =3D 'unknown'
    @comment  =3D 'Starbellied using sneetchalizer'
    @tracknum =3D 'unknown'
  end
  def to_s
    puts "Title: #@title"
    puts "Artist: #@artist"
    puts "Album: #@album"
    puts "Genre: #@genre"
    puts "Year: #@year"
    puts "Comment: #@comment"
    puts "Tracknum: #@tracknum"
  end
  def to_a
    ["#@title", "#@artist", "#@album", "#@genre", "#@year", "#@comment",=20
"#@tracknum"]
  end
end

class OggMetaTags < MetaTags
  attr_reader :title, :artist, :album, :genre, :year, :comment, :tracknum
  def initialize(filename)
    @filename =3D filename
    require 'ogginfo'
    @tags =3D OggInfo.new(@filename)
    @title =3D @tags.tag['title']
    @artist =3D @tags.tag['artist']
    @album =3D @tags.tag['album']
    @genre =3D @tags.tag['genre']
    @year =3D @tags.tag['date']
    @comment =3D super
    @tracknum ||=3D @tags.tag['tracknumber']
  end
end

> Calling a method will only do what the method code is set up to do.
Understood! About the only thing I understand now...

Thanks for the responses guys,
=2Dd
=2D-=20
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
=2D Dennis Ritchie and Ken Thompson, June 1972

--nextPart3734105.V7IelrB8Tr
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQBEhfO3wPD5Cr/3CJgRArg6AJ4xE/2foqe/MukmuG7nbNdL12FeVACfYsel
On35dXzMFDrSdg6WDZLyE0M=
=2ZcQ
-----END PGP SIGNATURE-----

--nextPart3734105.V7IelrB8Tr--