Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible fix for #4 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Possible fix for #4 #7

wants to merge 1 commit into from

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