Skip to content

Instantly share code, notes, and snippets.

@baweaver
Created January 17, 2021 05:53
Show Gist options
  • Save baweaver/af38da14fb682620faf6e35d966fad46 to your computer and use it in GitHub Desktop.
Save baweaver/af38da14fb682620faf6e35d966fad46 to your computer and use it in GitHub Desktop.
Quick example of the new Dio gem, https://www.github.com/baweaver/dio
require 'dio'
# Dive into arbitrary objects using their methods
Dio[1] in { succ: { succ: { succ: 4 } } }
# => true
Node = Struct.new(:value, :children)
tree = Node[1,
Node[2, Node[3, Node[4]]],
Node[5],
Node[6, Node[7], Node[8]]
]
# Dive into nested structures with no concept
# of pattern matching
Dio[tree] in {
value:,
children: [*, { value: 5 }, *]
}
# => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment