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
Should Enumerator#initialize check frozen status? #368
Conversation
* enumerator.c (enumerator_initialize): check frozen status after checking arity * test/ruby/test_enumerator.rb: test for above * test/ruby/test_lazy_enumerator.rb: ensure current behavior
The reason #initialize_copy raises an error on a frozen object is just because of its common behavior (see rb_obj_init_copy()) and it is not because Enumerator explicitly checks the frozenness. Plus, using a private method #initialize to modify an enumerator object is an unsupported operation and kind of abuse. To wrap up, my take is that Enumerator doesn't have the sense of frozenness, so there is no spec at the moment. Given that, I'm not sure we would want to decently implement the frozenness in Enumerator because a frozen enumerator, if at all, would have no use. Even #peek could change the state of the object, so all you could do with it is call #size or #inspect. There should be something better to do than pass an unusable object around. |
Thank you for sharing that with me! I felt strange Enumerator#initialize. This is because Regexp#initialize explicitly checking frozen and I don't know when using frozen Regexp. But I'm sure frozen Enumerator has no meanings and the implementation is needless. |
Actually, I didn't mean to reject this. What I wrote above was just an excuse for not eagerly supporting frozenness in Enumerator. |
* enumerator.c (enumerator_init): Add a frozenness check to prevent a frozen Enumerator object from being reinitialized with a different enumerable object. This is the least we should do, and more fixes will follow. [Fixes GH-368] Patch by Kenichi Kamiya. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
I'm happy with the results :) |
* enumerator.c (enumerator_init): Add a frozenness check to prevent a frozen Enumerator object from being reinitialized with a different enumerable object. This is the least we should do, and more fixes will follow. [Fixes rubyGH-368] Patch by Kenichi Kamiya. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ruby -v #=> ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
Frozen Enumerator can modify positions.
But it can't replace receiver-object/block on following methods.
Except Enumerator#initialize.
Is this a spec?