Show HN: String#to_proc` to Help Traversing JSON github.com · 2 points · 0 comme...
Show HN @show
Show HN: String#to_proc` to Help Traversing JSON github.com · 2 points · 0 comments · HN thread
TL;DR Sam Leb's Schmuck is a Ruby gem that adds String#to_proc, letting you write nested hash and array traversals as a path string such as '[data]*([customer][address][city])' and pass it as a block to map, then, or similar methods. The project is installable from GitHub but not yet on RubyGems, and the author asks whether it is worth releasing. The thread has no comments yet.
- A path string like '[data][repository][issues][edges]*([node][title])' is used as a block with then or map, replacing nested map/flat_map code.
- Syntax covers hash keys, symbol keys, indexes, method calls, a spread operator (*) that maps over arrays, and ? for nil-safe access.
- Unlike jq or JSONPath, paths are plain Ruby blocks, can call any Ruby method, do not auto-flatten arrays, and raise on nil by default.
- Paths are parsed at runtime and cached, so typos only surface when the code runs and editors cannot autocomplete them.
- It works by extending Symbol#to_proc's idea to strings, which means monkey-patching String.
- The gem is not on RubyGems.org yet; it is installed via a Git source in the Gemfile.
Discussion No one has commented on the post yet, so there is no discussion to summarize. The submission has 2 points and the author's question about whether a gem release is worthwhile is unanswered.