Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
strange arrayfields behaviour
Jean-Denis Muys
2/6/2009 2:42:00 PM
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/arrayfie...
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.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
strange arrayfields behaviour
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password