This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Cranking on the DBI rewrite
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Kirk, Francis and I have gotten rolling on the DBI rewrite. Well, at this point it's just a major refactoring. The "next gen" DBI is going to wait until we refactor the existing DBI package and apply patches for known bugs.
Last night I decided to take a whack at row.rb and see what I could improve on. It was quite the learning process. You see, DBI::Row is a delegate of Array, and stores a hash internally. This is why it behaves as both an Array and a Hash to allow you access column data by index or name.
That's handy, though I almost always reference by name rather than index, since you never know when an index just might change on you. Mind you, a column name could change to, but it's less likely.
What I didn't know was that you could actually get data using regular expressions, ranges and arrays as well. So, all of these are legal:
You can also do multiple arg references. This was a little goofy because in the case of 2 args (and only 2 args) it was decided to act like the second form of Array#[], i.e. the first value is the starting point and the second value is the length. If it's 3 or more arguments, it's more like a slice.