Skip to content

Instantly share code, notes, and snippets.

@kitallis
Created February 27, 2013 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitallis/5046010 to your computer and use it in GitHub Desktop.
Save kitallis/5046010 to your computer and use it in GitHub Desktop.
Module#prepend replacing :alias_method
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