Array#reject Does Not Retain Instance Variables
-----------------------------------------------

                 Key: JRUBY-5245
                 URL: http://jira.codehaus.org/browse/JRUBY-5245
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.5.6
         Environment: Mac OS X 10.6.5, JRuby 1.5.6 as installed by RVM
            Reporter: Paul Mucur
            Priority: Minor
         Attachments: array_reject_test.rb

Setting an instance variable on an array and then using Array#reject will cause 
the returned array to lose its state:

In C Ruby:

$ irb
ruby-1.8.7-p302 > a = []
 => [] 
ruby-1.8.7-p302 > a.instance_variable_set("@name", "Bob")
 => "Bob" 
ruby-1.8.7-p302 > a.reject {}.instance_variable_get("@name")
 => "Bob" 

In JRuby:

L3922:~ (jruby-1.5.6)
$ irb
a = [jruby-1.5.6 > a = []
 => [] 
jruby-1.5.6 > a.instance_variable_set("@name", "Bob")
 => "Bob" 
jruby-1.5.6 > a.reject {}.instance_variable_get("@name")
 => nil 

Note that the same doesn't apply for Enumerable#find_all which returns a new 
array populated with matching elements rather than copying the original array 
and deleting matching elements.

Simply #duping the array seems to work fine however:

jruby-1.5.6 > a.dup.instance_variable_get("@name")
 => "Bob" 

This came up due to will_paginate's storing of a @total_pages variable on an 
array which would be set to nil upon using #reject.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to