Skip to content

Instantly share code, notes, and snippets.

@hanachin
Created April 17, 2019 18:10
Show Gist options
  • Select an option

  • Save hanachin/db9a729f27ed4f51d63806a812d3848c to your computer and use it in GitHub Desktop.

Select an option

Save hanachin/db9a729f27ed4f51d63806a812d3848c to your computer and use it in GitHub Desktop.
def match?(obj)
case obj
in [1, 2, [3, 4]]
p :match
else
p :not_match
end
end
obj1 = Object.new
obj1.define_singleton_method(:deconstruct) do
p :obj1_deconstruct
obj2 = Object.new
obj2.define_singleton_method(:deconstruct) do
p :obj2_deconstruct
[obj1]
end
[1, 2, obj2]
end
match?(obj1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment