Created
February 27, 2013 07:40
-
-
Save kitallis/5046010 to your computer and use it in GitHub Desktop.
Module#prepend replacing :alias_method
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
class Earphone | |
def left | |
puts "Playing on left." | |
play(0) | |
end | |
def right | |
puts "Playing on right." | |
play(1) | |
end | |
# this. | |
def left_with_bit_rate | |
puts "Left with bit rate." | |
left_without_bit_rate | |
right_without_bit_rate | |
end | |
alias_method :left_without_bit_rate, :left | |
alias_method :left, :left_with_bit_rate | |
def right_with_bit_rate | |
puts "Right with bit rate." | |
right_without_bit_rate | |
end | |
alias_method :right_without_bit_rate, :right | |
alias_method :right, :right_with_bit_rate | |
private | |
def play(direction) | |
puts direction == 0 ? "Left" : "Right" | |
end | |
end | |
phone = Earphone.new | |
phone.left | |
phone.right |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment