Skip to content

Instantly share code, notes, and snippets.

@nagachika
Created April 19, 2013 16:06
Show Gist options
  • Save nagachika/5421349 to your computer and use it in GitHub Desktop.
Save nagachika/5421349 to your computer and use it in GitHub Desktop.
a joke example of refinements.
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
require_relative "husband"
using Secret
man = Husband.new
man.affair = "Beth"
puts "in the love nest"
man.say # => "I love Beth."
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