Created
May 30, 2018 08:36
-
-
Save pocke/1e0a7fc4b26fec6c0956e283b688ebab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def is_nil?(value, _=(value&.__id__(true&&return) rescue return)) | |
return true | |
end | |
p is_nil?(nil) | |
p is_nil?(false) | |
p is_nil?(true) | |
class A | |
undef __id__ | |
end | |
p is_nil?(A.new) | |
TracePoint.new(:call) do |tp| | |
tp.binding.local_variable_set :value, 'foo' if tp.method_id == :is_nil? | |
end.enable | |
p '---' | |
p is_nil?(nil) | |
p is_nil?(false) | |
p is_nil?(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment