Skip to content

Instantly share code, notes, and snippets.

@radixhound
Last active June 10, 2021 17:51
Show Gist options
  • Save radixhound/c14af0572f309e4c490617ee27874f7e to your computer and use it in GitHub Desktop.
Save radixhound/c14af0572f309e4c490617ee27874f7e to your computer and use it in GitHub Desktop.
module SecretKey
protected
def fix_plumbing(*args)
_fix_plumbing(*args) if defined?(:_fix_plumbing)
end
def twist_knob
_twist_knob if defined?(:_twist_knob)
end
end
class Matt
include SecretKey
private
def _fix_plumbing(house)
house.twist_knob
end
end
class House
include SecretKey
private
def _twist_knob
puts "squeak squeak"
end
end
class Jessica
include SecretKey
def ask_for_repair(plumber, house)
plumber.fix_plumbing(house)
end
end
class Sam
def fix_plumbing(house)
house.twist_knob
end
def ask_for_repair(plumber, house)
plumber.fix_plumbing(house)
end
end
jessica = Jessica.new
matt = Matt.new
jessica.ask_for_repair(matt, House.new)
# Sam isn't allowed in on the secret
sam = Sam.new
sam.fix_plumbing(House.new)
sam.ask_for_repair(matt, House.new)
@geeksam
Copy link

geeksam commented Jun 10, 2021

I feel excluded. 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment