Created
May 22, 2011 12:27
-
-
Save Amokrane/985423 to your computer and use it in GitHub Desktop.
respond_to? And method_missing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This snippet is taken from: | |
# "The Polite Programmer's Guide to Ruby Etiquette" | |
# http://bit.ly/hrwdPY | |
class BlackMagicStereo < Stereo | |
def method_missing(name, *args) | |
if sym.to_s =~ /^play_(\w+)$/ | |
system("open songs/#{$1}.m4a") | |
else | |
# Here, very important! | |
# Don't forget to delegate up to previous implementation | |
super | |
end | |
end | |
end | |
def respond_to?(name) | |
sym.to_s =~ /^play_/ || super | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment