Created
April 19, 2013 16:06
-
-
Save nagachika/5421349 to your computer and use it in GitHub Desktop.
a joke example of refinements.
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 Husband | |
attr_accessor :affair | |
def say | |
puts "I love my wife." | |
end | |
end | |
module Secret | |
refine Husband do | |
def say | |
if @affair | |
puts "I love #{@affair}." | |
else | |
super | |
end | |
end | |
end | |
end |
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
require_relative "husband" | |
using Secret | |
man = Husband.new | |
man.affair = "Beth" | |
puts "in the love nest" | |
man.say # => "I love Beth." |
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
require_relative "husband" | |
man = Husband.new | |
man.affair = "Beth" | |
puts "In public space" | |
man.say # => "I love my wife." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment