# Strange arrayfields behaviour

**URL:** <https://www.ruby-forum.com/t/strange-arrayfields-behaviour/159639>\
**Category:** Ruby\
**Created:** [February 6, 2009, 3:42pm UTC](https://www.ruby-forum.com/t/strange-arrayfields-behaviour/159639 "2009-02-06T15:42:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-Denis\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/94ad74/32.png) [@Jean-Denis\_M](https://www.ruby-forum.com/u/Jean-Denis_M)\
**Post date:** [February 6, 2009, 3:42pm UTC](https://www.ruby-forum.com/t/strange-arrayfields-behaviour/159639/1 "2009-02-06T15:42:49Z")

</div>

Here is a counterintuitive behaviour of the arrayfields.rb module.

It’s suppose to add light “indexing by keywords” capabilities to the  
Array  
class, without going all the way to hashes.

See [http://rubyfurnace.com/docs/arrayfields-3.7.0/](http://rubyfurnace.com/docs/arrayfields-3.7.0/)

However, after deleting items from an array, there is mismatch in the  
fields.

Here is a small example:

> > require ‘arrayfields’  
> > =\> true  
> > ar = [1, 2, 3]  
> > =\> [1, 2, 3]  
> > ar.fields = [“one”, “two”, “three”]  
> > =\> [“one”, “two”, “three”]  
> > ar[1]  
> > =\> 2  
> > ar[“two”]  
> > =\> 2  
> > ar  
> > =\> [1, 2, 3]  
> > ar.delete\_at(“two”) # \*\*\*\*\*\* delete ar[“two”] \*\*\*\*\*\*  
> > =\> 2  
> > ar[“two”] # \*\*\*\*\*\* but there still is an ar[“two”] \*\*\*\*\*\*  
> > =\> 3  
> > ar  
> > =\> [1, 3]  
> > ar[“one”]  
> > =\> 1  
> > ar[“three”]  
> > =\> nil  
> > ar.keys  
> > =\> [“one”, “two”, “three”]

I don’t believe this is a bug. But this bit me.  
Lesson learned: arrayfields don’t a Hash make.
