From: Chad Perrin Date: 2010-10-22T11:15:19+09:00 Subject: Re: Help needed with this code please --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 22, 2010 at 07:03:04AM +0900, Paul Roche wrote: > class Song [snip] > > @@songs =3D [ ] [snip] >=20 > def self.list > @@songs > end >=20 > def self.list_add=3D(val) > @@songs << val > end >=20 > end [snip] >=20 > module Tuneuts > def self.fetch(item, out =3D []) > all =3D Song.list + Actor.list + Album.list + Library.list [snip] > end > end >=20 > The problem is Song.list (in the module Tuneuts) is returning nothing. > Am I missing something here? Maybe I'm missing something obvious, but I think the parts I didn't snip out are the relevant bits: Are you, at any point before calling Song.list, assigning anything to the @@songs variable? From what I've seen, your @@songs variable is just an empty list at the point you call Song.list in the Tuneuts module. As such, it should be returning "nothing", in that it returns nothing but an empty list. Note that in my irb examples, I've saved all the code that was included inline in your email in a single file called song.rb, and commented out the `require "predicate"` part -- and moved the Pred module definition above the Song class definition so the class could actually take advantage of the module. ~> irb irb(main):001:0> load 'song.rb' =3D> true irb(main):002:0> Song.list =3D> [] irb(main):003:0> puts Song.list =3D> nil If you assign something to it using your list_ad=3D method, however, you'll then get something out of it: irb(main):004:0> Song.list_add =3D 'foo' =3D> "foo" irb(main):005:0> Song.list =3D> ["foo"] irb(main):006:0> puts Song.list foo =3D> nil Is that perhaps where you're having a problem? --=20 Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] --YiEDa0DAkWCtVeE4 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAkzA8nkACgkQ9mn/Pj01uKUk1ACfQh6//f9IytwIOkSHxtbSLrEI tfkAoOZ82koY2/gBojrkm8gYkckz5IqJ =3+QI -----END PGP SIGNATURE----- --YiEDa0DAkWCtVeE4--