# More fixes for core/array specs

**URL:** <https://www.ruby-forum.com/t/more-fixes-for-core-array-specs/165854>\
**Category:** IronRuby\
**Created:** [April 18, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/more-fixes-for-core-array-specs/165854 "2009-04-18T13:35:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [April 18, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/more-fixes-for-core-array-specs/165854/1 "2009-04-18T13:35:18Z")

</div>

Hi,

> <https://github.com/nrk/ironruby/commit/4afc7f1bc44b007a9dca30e6330eca35d487f165>
>
> \* Fix IoOps.ToPrintedString to output a double converted to string using an inva…riant culture (Issue #597 NumericLiterals1 test fails under french culture)
> 
> \* IListOps.ValuesAt adds a null value to the result if the begin value of the specified range instance(s) is \<= the length of the array and the end value is \>= the length of the array.
> 
> \* Array#uniq! raises a TypeError on a frozen array if modification would take place.
> 
> \* Fixed ArrayOps.ToArray to return a new RubyArray instance with the elements of self if self is a RubyArray.Subclass.
> 
> \* Array#initialize with (size, object=nil) uses the block value instead of using the default value
> 
> \* Fixed IListOps.Compare to work with recursive arrays.

This commit resolves the following failing specs:

Array#\<=\> properly handles recursive arrays (critical)  
Array#initialize with (size, object=nil) uses the block value instead  
of using the default value  
Array#to\_a does not return subclass instance on Array subclasses  
Array#uniq! raises a TypeError on a frozen array if modification would  
take place  
Array#values\_at returns an array of elements in the ranges when passes  
ranges

> From the commit message:

- Removed unused allocateStorage argument from IListOps.First and  
IListOps.Last; Removed the manual protocol conversion bits in  
IListOps.Fetch
- Fix IoOps.ToPrintedString to output a double converted to string  
using an invariant culture (Issue #597 NumericLiterals1 test fails  
under french culture)
- IListOps.ValuesAt adds a null value to the result if the begin value  
of the specified range instance(s) is \<= the length of the array and  
the end value is \>= the length of the array.
- Array#uniq! raises a TypeError on a frozen array if modification  
would take place.
- Fixed ArrayOps.ToArray to return a new RubyArray instance with the  
elements of self if self is a RubyArray.Subclass.
- Array#initialize with (size, object=nil) uses the block value  
instead of using the default value
- Fixed IListOps.Compare to work with recursive arrays.

A diff is attached to this mail.

PS: This completes my previous commit by removing unused  
allocateStorage arguments from IListOps.First and IListOps.Last.

Thanks,  
Daniele

---

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [April 19, 2009, 12:59am UTC](https://www.ruby-forum.com/t/more-fixes-for-core-array-specs/165854/2 "2009-04-19T00:59:17Z")

</div>

Hi,

just a self-reply to point out that the changes in ArrayOps.ToArray  
introduced a regression for Array#to\_ary (reported by  
core/array/to\_ary) due to the different behaviour of Array#to\_a and  
Array#to\_ary on subclasses of Array. I have already fixed this on my  
local repository, I’m just waiting to have a few more commits to  
rebase and push the next set of changes on github.

On Sat, Apr 18, 2009 at 13:31, Daniele A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Array#uniq! raises a TypeError on a frozen array if modification would  
> under french culture)
> 
> [clorophilla.net](http://www.clorophilla.net/blog/)  
> [http://twitter.com/JoL1hAHN](http://twitter.com/JoL1hAHN)

–  
Daniele A.  
[http://www.clorophilla.net/blog/](http://www.clorophilla.net/blog/)  
[http://twitter.com/JoL1hAHN](http://twitter.com/JoL1hAHN)

---

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [April 19, 2009, 1:10am UTC](https://www.ruby-forum.com/t/more-fixes-for-core-array-specs/165854/3 "2009-04-19T01:10:58Z")

</div>

Looks good!

In IListOps.UniqueSelf, any reason you do “bool frozen =  
context.IsObjectFrozen(self);” upfront instead doing IsObjectFrozen when  
you actually need it? If uniq! Is called on a  
System.Collections.Generic.List, IsObjectFrozen will be expensive  
since we have to keep the “frozen” bit on the side. (For RubyArray, we  
will keep the bit as an instance field which will be cheap to access).  
So for List objects which are already unique, it will be faster if  
you can avoid doing IsObjectFrozen.

Note that simplicity trumps optimization unless you have hard data that  
the optimization is required. I am only suggesting this optimization as  
its trivial, and the code is as simple in either case…

---

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [April 20, 2009, 10:59am UTC](https://www.ruby-forum.com/t/more-fixes-for-core-array-specs/165854/4 "2009-04-20T10:59:37Z")

</div>

Good point, and I guess there is no real reason for doing that… it  
wasn’t really an attempt to achieve optimization, it just turned out  
like that as I honestly totally missed the case of already unique  
lists 🙂 Adjustments scheduled for the next push of my commits.

On Sun, Apr 19, 2009 at 01:10, Shri B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Subject: Re: [Ironruby-core] More fixes for core/array specs
> 
> > Array#to\_a does not return subclass instance on Array subclasses  
> > using an invariant culture (Issue #597 NumericLiterals1 test fails
> > 
> > - Fixed IListOps.Compare to work with recursive arrays.  
> > Daniele A.
> 
> * * *
> 
> Ironruby-core mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
> 
> * * *
> 
> Ironruby-core mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Daniele A.  
[http://www.clorophilla.net/blog/](http://www.clorophilla.net/blog/)  
[http://twitter.com/JoL1hAHN](http://twitter.com/JoL1hAHN)
