psych icon indicating copy to clipboard operation
psych copied to clipboard

Toplevel [] method for YAML?

Open rubyFeedback opened this issue 1 year ago • 1 comments

Would it be possible to alias YAML[] onto YAML.load_file()?

E. g.:

x = YAML.load_file('foobar.yml')
x = YAML['foobar.yml']

Rationale:

Laziness (or "user efficiency" - anything to type less, just as require 'pp' is no longer necessary. :D

rubyFeedback avatar Aug 01 '24 14:08 rubyFeedback

Is there any precedent for such an alias? Are there other libraries that alias one of their methods to a module-level []? I have to admit it looks a little weird to my eyes.

There's another Ruby quirk that could be used instead: YAML.(), which Ruby treats as a call to YAML.call. The more you know! 🌠

headius avatar Aug 01 '24 19:08 headius