--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi Darren,

On Sun, Jun 11, 2006 at 03:13:30AM +0900, darren kirby wrote:
> Hello all,
> 
> I am scratching my head over this one.
> I have a method:
> 
> def dispatchFile(file)
>   song = Convert.new(file)
>   case type
>   when 'ogg'
>     song.oggToWav
>     song.wavToOgg  if $outtype == 'ogg'
>     song.wavToMp3  if $outtype == 'mp3'
>     song.wavToM4b  if $outtype == 'm4b'
>     song.wavToFlac if $outtype == 'flac'
>   when 'mp3'
> <etc....>
>   end
> end

    Some suggestions:

    1) I would calculate the method name dinamically with $outtype, insteadf
having 4 if constructions. Something like:

    song.send "wavTo#{$outtype.capitalize}"

    2) I wouldn't use a global variable anyway. I think it's better sending
the out type as a parameter.
    3) What is "type", a method? It should probably also be a parameter for
dispatchFile, but I don't know if that's a function or a method.
    4) Wouldn't it be better having dispatchFile as a Convert method? Perhaps
with other name, but...

> When I run this code the 'if's are never evaluated. That is, I have printed 
> $outtype, and it has a valid value, but the second method which matches the 
> value never runs. If I comment out the 'if' and run the two methods manually 
> it works fine.
> 
> In my tests $outtype's value is 'mp3', so why doesn't song.wavToMp3 run?
> What am I missing?

    I made a quick test and it worked for me, but I don't know the rest of
your code. This is the example that worked:

------------------------------------- 8< -------------------------------------
class Convert
    def initialize(file); end

    def oggToWav;  puts "oggToWav"; end
    def wavToOgg;  puts "wavToOgg"; end
    def wavToMp3;  puts "wavToMp3"; end
    def wavToM4b;  puts "wavToM4b"; end
    def wavToFlac; puts "wavToFlac"; end
end

def type; "ogg"; end

$outtype = 'mp3'

def dispatchFile(file)
  song = Convert.new(file)
  case type
  when 'ogg'
    song.oggToWav
    song.wavToOgg  if $outtype == 'ogg'
    song.wavToMp3  if $outtype == 'mp3'
    song.wavToM4b  if $outtype == 'm4b'
    song.wavToFlac if $outtype == 'flac'
  when 'mp3'
    puts "mp3 nsbb"
  end
end


dispatchFile('foo')
------------------------------------- >8 -------------------------------------

It printed "oggToWav" and "wavToMp3".  It probably has nothing to do with
global variables not evaluating, but I can't tell without seeing the rest of
the code.

    Regards,

-- 
Esteban Manchado VeláÛquez <zoso / foton.es> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es

--HcAYCG3uE/tztfnV
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

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

iD8DBQFEixjQhYgK5b1UDsERAk0WAJkBp9z3iIXQkU9L6CDAiu+rn+dY+wCeP35Z
z3FyKPgOyxh8P6J/1IDwuaIBv
-----END PGP SIGNATURE-----

--HcAYCG3uE/tztfnV--