Working with Tags
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 597
- Forks
- 223
- Avg merge
- 11h 23m
- Merged PRs (30d)
- 3
Description
I noticed today that an undefined tag appears to be simply thrown away.
o = YAML.load('--- !foo "something"') #=> "something"
o.class #=> String
I actually expected it to raise an error, and was somewhat pleased that it did not. But without the tag it's not much use in any case. What would be useful is a YAML wrapper around the object that delegates to it, but also provides a #tag method (and anything else that YAML might need), something like:
o = YAML.load('--- !foo "something"') #=> <!foo "something">
o.tag #=> "!foo"
o.to_obj #=> "something"
This would make working with YAML documents that use tags much easier, b/c it would mean handlers would not have to be defined upfront and with necessary pre-knowledge. Rather they could be handled on the fly and even dynamically if desired.
I've been thinking about this for some time as I routinely find myself avoiding any use of YAML tags simply b/c of the cumbersome nature of handling them.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the YAML.load example in the issue and trace how an undefined !foo tag is currently handled. Define the wrapper behavior around the tagged value, including tag access and conversion to the underlying object. Done means tagged YAML values retain their tag and can still expose the wrapped value without requiring a handler in advance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby, yaml
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100