strange arrayfields behaviour

  • Thread starter Jean-Denis Muys
  • Start date
J

Jean-Denis Muys

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/

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top