On Tuesday, September 11, 2012 5:22:10 PM UTC-4, Masterleep wrote:
>
> Maybe something like a StringPool
That's a big one, and it would be something that needs to be addressed in
Ruby, not in Rails. But the problem is that you would have unintuitive
behavior for those used to doing things like:
s = 'Error'
s.chomp!('or')
In today's Ruby and jruby-1.7.0.preview2:
$ irb
jruby-1.7.0.preview2 :001 > "Error".object_id
=> 2042
jruby-1.7.0.preview2 :002 > "Error".object_id
=> 2044
jruby-1.7.0.preview2 :003 > "Error".chomp!('or').object_id
=> 2046
jruby-1.7.0.preview2 :004 > s = "Error"
=> "Error"
jruby-1.7.0.preview2 :005 > s.object_id
=> 2048
jruby-1.7.0.preview2 :006 > s.chomp!('or')
=> "Err"
jruby-1.7.0.preview2 :007 > s.object_id
=> 2048
See, when you are just working with strings willy nilly, it creates new
instances and you don't have to worry about things like the "bang" methods
altering the same object.
In a StringPool'd ruby, the bang methods would need to return a string that
was the same object_id so that past implementations that depend on object
equivalence would still work, but it could not alter the "Error" string in
the StringPool or things would go terribly wrong.
Feel free to take this up on the ruby list, and post back the link. I'm
sure that those guys could figure out a way to make it work if they've not
already discussed it, but my guess is it would be a breaking major change,
even if it is necessary to reduce # of objects and make things faster.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/GbH73B1EQmQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.