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

Add to_b and to_h to JS::Object #346

Open
terrablue opened this issue Dec 16, 2023 · 3 comments
Open

Add to_b and to_h to JS::Object #346

terrablue opened this issue Dec 16, 2023 · 3 comments

Comments

@terrablue
Copy link
Contributor

I would like to suggest adding to_b and to_h to JS::Object, to convert into a ruby boolean respective hash.

to_b → boolean
Converts self to true or false:

JS.eval("return true").to_b        # => true
JS.eval("return false").to_b       # => false

to_h → hash
Converts self to a Hash:

JS.eval("return {foo: 'bar'}").to_h         # => { "foo" => "bar" }
@kateinoigakukun
Copy link
Member

For to_b, I intentionally didn't add it. See #247 for details.

@terrablue
Copy link
Contributor Author

I understand. So in that case I can implement it myself for my use case. What about to_h? It's already used in this meaning in ruby, no?

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Dec 16, 2023

Right, to_h sounds reasonable to me. I think that would be something like #270. Note that the conversion should be shallow, not recursive, to follow the usual Ruby to_h convention. See OpenStruct#to_h as an example.

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

No branches or pull requests

2 participants