Last active
October 4, 2021 12:27
-
-
Save searls/651c9985bc6d747c02650a70bcd573a0 to your computer and use it in GitHub Desktop.
method_missing will catch private methods. Makes sense, but TIL
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 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