Amokrane
5/22/2011 - 12:32 PM

Making an alias of the method_missing

Making an alias of the method_missing

# This snippet is taken from:
# "The Polite Programmer's Guide to Ruby Etiquette" 
# http://bit.ly/hrwdPY

class BlackMagicStereo < Stereo
  # Make an alias of the previous method_missing definition
  alias method_missing_without_show method_missing

  def method_missing(name, *args, &block)
    if sym.to_s =~ /^play_(\w+)$/
      system("open songs/#{$1}.m4a")
    else 
      method_missing_without_show(name, *args, &block)
    end
   end
end