From: darren kirby Date: 2006-06-07T05:25:04+09:00 Subject: Attributes not populated until called? --nextPart6307730.ZOWed5RUTu Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello all, Pretty much new to Ruby, and I think I am not grasping something fundamenta= l=20 here. I've written some classes that grab meta tags from various audio file= =20 formats, and overrode 'to_s" to dump the tags to the console, and "to_a" to= =20 dump the tags to an array for use elsewhere in my program. I am not sure how to explain my problem, so I will just paste in a session= =20 from irb that shows it: irb> require 'sneetchalizer' # my class definitions... irb> x =3DOggMetaTags.new('/home/music/e/elliottSmith-shootingStar.ogg') =3D> # x.to_a =3D> ["", "", "", "", "", "", ""] irb> x.title =3D> "Shooting Star" irb> x.to_a =3D> ["Shooting Star", "", "", "", "", "", ""] irb> x.artist =3D> "Elliott Smith" irb> x.to_a =3D> ["Shooting Star", "Elliott Smith", "", "", "", "", ""] So you can see I need to explicitly call each attribute before my array get= s=20 the value. How can I change this so the array is populated automatically wh= en=20 called? Here is the class: class OggMetaTags < MetaTags def initialize(filename) @filename =3D filename require 'ogginfo' @tags =3D OggInfo.new(@filename) end def title @title =3D @tags.tag['title'] end def artist @artist =3D @tags.tag['artist'] end def album @album =3D @tags.tag['album'] end def genre @genre =3D @tags.tag['genre'] end def year @year =3D @tags.tag['date'] end def comment @comment =3D super end def tracknum @tracknum =3D @tags.tag['tracknumber'] end def to_a ["#@title", "#@artist", "#@album", "#@genre", "#@year", "#@comment",=20 "#@tracknum"] end end If you need more info or want to see all the code please just ask. Thanks f= or=20 consideration, =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 --nextPart6307730.ZOWed5RUTu Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQBEheSawPD5Cr/3CJgRArgBAJ9oNB5OuEApzrwBvhdvmruInb24IgCfclYp rOhxXyvySmRl9BgaQNyzXx8= =aNUE -----END PGP SIGNATURE----- --nextPart6307730.ZOWed5RUTu--