Skip to content

Instantly share code, notes, and snippets.

@searls
Last active October 4, 2021 12:27
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 searls/651c9985bc6d747c02650a70bcd573a0 to your computer and use it in GitHub Desktop.
Save searls/651c9985bc6d747c02650a70bcd573a0 to your computer and use it in GitHub Desktop.
method_missing will catch private methods. Makes sense, but TIL
class Hmm
def method_missing(name)
"missing #{send(name)}"
end
def respond_to_missing?(name, include_all = false)
true
end
def beef?
"🥩"
end
private
def ham?
"🐷"
end
end
puts Hmm.new.beef? #=> "🥩"
puts Hmm.new.ham? #=> "missing 🐷"
puts Hmm.new.send(:ham?) #=> "🐷"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment