Skip to content

Possible fix for #4#7

Open
jcward wants to merge 1 commit intobbc:masterfrom
jcward:patch-2
Open

Possible fix for #4#7
jcward wants to merge 1 commit intobbc:masterfrom
jcward:patch-2

Conversation

@jcward
Copy link

@jcward jcward commented Oct 12, 2017

Reasonable hack: makes all hashes get Hash suffix instead of Array suffix
Makes stringify {} output []Hash instead of []Array.

Reasonable hack: makes all hashes get `Hash` suffix instead of `Array` suffix
Makes stringify `{}` output `[]Hash` instead of `[]Array`.
@samfrench
Copy link
Contributor

If we were to do this then I would suggest gsub, as this only replaces the first occurrence:

Crimp.stringify({foo:{}}).sub(/Array$/, 'Hash')
=> "[\"fooSymbol=>[]Array\"]Hash"

But not sure I agree with fixing this. I commented on #4 about this.

@jcward
Copy link
Author

jcward commented Oct 13, 2017

Replacing only the Array at the end is the intent (hence /Array$/).

This PR observes that parse_array and parse_hash both return [<some recursive content>]Array -- and it merely says for parse_hash, let's replace that trailing Array to make it [<some recursive content>]Hash. A recursive gsub would modify the <some recursive content> be destructive to the recursive nature of the stringification.

Again, I don't care what you do with this PR, I'm just putting it out there for others consideration. Cheers!

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