Skip to content

Instantly share code, notes, and snippets.

@hanachin
Last active November 19, 2019 04:20
Show Gist options
  • Save hanachin/b0299b373118c3fb9f585329ffe13fc8 to your computer and use it in GitHub Desktop.
Save hanachin/b0299b373118c3fb9f585329ffe13fc8 to your computer and use it in GitHub Desktop.
tp = TracePoint.new(:call) do |tp|
next unless tp.method_id == :===
$v = tp.self
end
tp.enable
class C
def deconstruct_keys(keys)
result = {}
result[:k] = $v
result
end
end
class Hoge
class << self
def ===(other)
true
end
end
end
class Fuga
class << self
def ===(other)
true
end
end
end
c = C.new
case c
in Hoge(k: v)
puts v
end
case c
in Fuga(k: v)
puts v
end
# yami.rb:33: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
# yami.rb:38: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
# Hoge
# Fuga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment