[ANN] arrayfields-3.1.0 - the kirk haines release

as kirk haines right pointed out, i was not handling memory in the most
efficient manner in the 3.0.0 release. this release (3.1.0) should remedy
that with a single change to the interface. thanks kirk.

URLS:

   - http://raa.ruby-lang.org/project/arrayfields/
   - http://www.codeforpeople.com/lib/ruby/arrayfields/

SYNOPSIS:

   allow keyword access to arrays:

     require 'arrayfields'

     fields = 'name', 'age'
     row = [ 'bob', 30 ]

     row.fields = fields

     row[ 'name' ] #=> 'bob'
     row.indices 'name', 'age' #=> [ 'bob', 30 ]

   assigning to un-named fields appends:

     stack =
     stack.fields = %w(zero one)
     stack['zero'] = 'zero'
     stack['one'] = 'one'
     stack #=> [ 'zero', 'one' ]

   useful for database work:

     relation = pgconn.query sql
     relation.size #=> 65536

     # yikes! do we really want to re-construct a hash for for each tuple when
     # we already have Arrays?

     fields = %w(ssn name position)
     table.each{|tuple| tuple.fields = fields}

     tuples[34578]['ssn'] #=> 574865032

LIST OF OVERRIDDEN METHODS:

   - Array#
   - Array#=
   - Array#at
   - Array#delete_at
   - Array#fill
   - Array#values_at
   - Array#indices
   - Array#indexes
   - Array#slice
   - Array#slice!

LIST OF NEW Array METHODS:

   - Array#fields=
   - Array#each_with_field

DOCS/USAGE/SAMPLE:

   - lib/arrayfields.rb
   - test/arrayfields.rb

AUTHOR:

   ara.t.howard@noaa.gov

HISTORY:

   3.1.0:
     - added FieldSet class to reduce ram - thnx. Kirk Haines for profiliing
       memory and prompting this change

     - interface changed every so slightly so

         a.fields = 'a', 'b', 'c'

       is not allowed. use

         a.fields = %w(a b c)

       or

         a.fields = ['a', 'b', 'c']

   3.0.0:
     - added unit tests

-a

···

--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen

===============================================================================

Hi,

At Wed, 30 Jun 2004 10:42:54 +0900,
Ara.T.Howard wrote in [ruby-talk:104887]:

as kirk haines right pointed out, i was not handling memory in the most
efficient manner in the 3.0.0 release. this release (3.1.0) should remedy
that with a single change to the interface. thanks kirk.

$ ruby-1.8 -r arrayfields-3.0.0 -e 'a=' -e 'a.fields=[:a]' -e 'a[:x]=1' -e 'p a[:x]'
1
$ ruby-1.8 -r arrayfields-3.1.0 -e 'a=' -e 'a.fields=[:a]' -e 'a[:x]=1' -e 'p a[:x]'
./arrayfields-3.1.0.rb:73:in `=': undefined method `=' for nil:NilClass (NoMethodError)
  from -e:3

@fieldpos still remains outside FieldSet.

--- arrayfields-3.1.0.rb 2004-06-30 09:35:55.000000000 +0900
+++ arrayfields.rb 2004-06-30 12:28:14.000000000 +0900
@@ -57,5 +57,5 @@
     def (idx, *args)
#{{{
- if @fieldset and String === idx or Symbol === idx
+ if @fieldset and (String === idx or Symbol === idx)
         pos = @fieldset.pos idx
         return nil unless pos
@@ -69,7 +69,7 @@
     def =(idx, *args)
#{{{
- if @fieldset and String === idx or Symbol === idx
+ if @fieldset and (String === idx or Symbol === idx)
         pos = @fieldset.pos idx
- @fieldpos[idx] = pos = size unless pos
+ @fieldset.fieldpos[idx] = pos = size unless pos
         super(pos, *args)
       else
@@ -80,5 +80,5 @@
     def at idx
#{{{
- if @fieldset and String === idx or Symbol === idx
+ if @fieldset and (String === idx or Symbol === idx)
         pos = @fieldset.pos idx
         return nil unless pos
@@ -91,5 +91,5 @@
     def delete_at idx
#{{{
- if @fieldset and String === idx or Symbol === idx
+ if @fieldset and (String === idx or Symbol === idx)
         pos = @fieldset.pos idx
         return nil unless pos
@@ -103,5 +103,5 @@
#{{{
       idx = args.first
- if idx and @fieldset and String === idx or Symbol === idx
+ if idx and @fieldset and (String === idx or Symbol === idx)
         idx = args.shift
         pos = @fieldset.pos idx

···

--
Nobu Nakada

<snip patch>

should all be fixed in 3.2.0 in the RAA.

thanks - long day :wink:

-a

···

On Wed, 30 Jun 2004 nobu.nokada@softhome.net wrote:

$ ruby-1.8 -r arrayfields-3.0.0 -e 'a=' -e 'a.fields=[:a]' -e 'a[:x]=1' -e 'p a[:x]'
1
$ ruby-1.8 -r arrayfields-3.1.0 -e 'a=' -e 'a.fields=[:a]' -e 'a[:x]=1' -e 'p a[:x]'
/arrayfields-3.1.0.rb:73:in `=': undefined method `=' for nil:NilClass (NoMethodError)
  from -e:3

@fieldpos still remains outside FieldSet.