From: darren kirby Date: 2006-06-08T04:18:17+09:00 Subject: Re: Attributes not populated until called? --nextPart31081583.kbzPM34DCG Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline quoth the Daniel Sheppard: > > Ok, so I changed the code so the assignments are in > > initialize(). Now I am > > getting some broken behavior. First of all, most of the tags > > are getting set > > by the super class which is only supposed to happen if the > > tag is 'comment': > > ... > > > @comment =3D super > > That line calls the initialize() method from your superclass and assigns > the result of that method (coming from the last line "@tracknum =3D > 'unknown'") to the @comment variable. Why does it do this? I thought it would run the 'comment' method in the=20 superclass. That is what I was trying to do anyway. In the bigger picture, = I=20 have this: MetaTags OggMetaTags Mp3MetaTags M4aMetaTags I have a little wrapper function that checks the filetype you pass to it, t= hen=20 dispatches the appropriate tag handling class to return the tags for use. I= f=20 the file is not an ogg, m4a, or mp3 then the defaults should be created usi= ng=20 MetaTags. I am trying to make this as transparent as possible. ie: you pass= =20 it a filename, and it returns an array of tags, doing the right thing=20 internally. > What you probably want is: Can you define a module in the same file as where you call it? I am not su= re=20 why you would do it this way instead of simply adding to_a and to_s in=20 MetaTags? Can you explain why you suggest to do it this way? Please remembe= r=20 I am just learning Ruby and I do appreciate a bit of explainaition so I mig= ht=20 learn some good style.. > module TagDisplayer > ATTRIBUTES =3D %w{title artist album genre year comment tracknum} > attr_reader *ATTRIBUTES > def to_a > ATTRIBUTES.map {|x| send(x)} > end > def to_s > ATTRIBUTES.map {|x| "#{x.capitalize}: #{send(x)}" > }.join("\n") > end > end > > class MetaTags > include TagDisplayer > 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 > end > > class OggMetaTags < MetaTags > include TagDisplayer > 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 'Starbellied using sneetchalizer' > @tracknum =3D @tags.tag['tracknumber'] > end > end Thanks for the help Daniel, and everybody else. It is appreciated. =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 --nextPart31081583.kbzPM34DCG Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQBEhyZ2wPD5Cr/3CJgRAncDAKCSsx5tZ1zNhgIi6iUrTv8we3EU5gCeNiva 08YZgvHZpiL9OMLa7cBvSGw= =3/Gw -----END PGP SIGNATURE----- --nextPart31081583.kbzPM34DCG--