Skip to content

Instantly share code, notes, and snippets.

@pocke
Created May 30, 2018 08:36
Show Gist options
  • Save pocke/1e0a7fc4b26fec6c0956e283b688ebab to your computer and use it in GitHub Desktop.
Save pocke/1e0a7fc4b26fec6c0956e283b688ebab to your computer and use it in GitHub Desktop.
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