Closed taichi-ishitani closed 1 year ago
Opal (https://opalrb.com) doesn't support private and protected modifiers and this support unfortunately isn't planned anytime soon.
Hi @hmdne , Thank you for your comment and I understood.
Rather than open another issue, I'm going to add this here.
I was trying to answer a friend's questions about Ruby from my phone and resorted to TryRuby, but it turns out some things behave fundamentally differently:
Scenario | IRB/MRI | TryRuby |
---|---|---|
[String and Symbol equality](https://github.com/ruby/spec/blob/f30dad390c47a436465abc2ff62c4a863bdb3299/core/symbol/equal_value_spec.rb#L12) | ```ruby :a == "a" # => false ["a"].include?(:a) # => false ``` | ```ruby :a == "a" # => true ["a"].include?(:a) # => true ``` |
String and Symbol Object IDs | ```ruby :a.object_id # => 759068 "a".object_id # => 260 ``` | ```ruby :a.object_id # => "a" "a".object_id # => "a" ``` |
These are a fundamental difference in how symbols work and very misleading for anyone trying to get an understanding of why symbols exist and how they differ from strings.
Perhaps it is worth noting for the user that there may be subtle differences between what they see here and in other implementations?
Edit: I see this appears to be because Opal doesn't actually distinguish between Symbol
and String
at all?
Symbol == String # => true
That explains it, but still feels weird to see when trying to show off Ruby, since Symbols
are so widely used, and new to some people.
We provided the WASM implementation of CRuby now. You can try it and get the same results of MRI.
Ahh, I see. It is only available in the playground though. Would it make sense to use this as default on the home page?
I think the first step is to clarify Opal is the currently default, and make it possible to use CRuby on the homepage: https://github.com/ruby/TryRuby/issues/122.
Then switching to CRuby by default can be chosen after that.
Fixed by #148
Result of following code are different between TryRuby and MRI.
Result of TryRuby
Result of MRI