Skip to content

Adding an option to dump symbols in a more natural format#2

Open
camertron wants to merge 1 commit into
afunai:masterfrom
camertron:natural_symbols
Open

Adding an option to dump symbols in a more natural format#2
camertron wants to merge 1 commit into
afunai:masterfrom
camertron:natural_symbols

Conversation

@camertron

Copy link
Copy Markdown

The current ya2yaml dump of a Ruby symbol looks like this:

:batman.ya2yaml

--- !ruby/symbol batman

While this works, it's a little hard on the eyes. Symbols as hash keys are even worse:

{ :batman => "dark knight" }.ya2yaml

--- 
? !ruby/symbol batman
: "dark knight"

The Ruby YAML parser knows how to deal with symbols natively using the colon syntax, so why not output them that way? This pull request adds an option to #ya2yaml called :use_natural_symbols that emits symbols prefixed by the more familiar colon:

:batman.ya2yaml(:use_natural_symbols => true)

--- :batman

{ :batman => "dark knight" }.ya2yaml(:use_natural_symbols => true)

--- 
:batman: "dark night"

@nsallembien

Copy link
Copy Markdown

I am strongly in favor of this pull request :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants