The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Spreadsheet II: The Spreadsheet Strikes Back

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Spreadsheet II: The Spreadsheet Strikes Back Posted: Oct 13, 2005 9:28 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Spreadsheet II: The Spreadsheet Strikes Back
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
I've had 3 releases of the spreadsheet package in as many days. The first one didn't get along with gems. The second one didn't get along with Windows. Now I'm discovering that the third one doesn't get along with StringIO.

It's not my fault! The check is in the mail! She was dead when I got there! Etc, etc.

The problem stems from the fact that, in proper duck typing fashion, Excel.new checks to see if the argument responds to a fileno method. There is a StringIO#fileno, but it always returns nil. Kerblooey.

I say it's not my fault, because there's no way to automatically delegate IO methods to a StringIO object as far as I can tell. Consider:
require "stringio"

sio = StringIO.new
io = IO.open(sio, "w+") # Boom!

That won't work. I don't see any way to make that work without special handling in, say, a subclass. However, since I *am* dealing with a subclass (OLEWriter), I *could* make it work. The only solution I see is to do a type check (ick) in the constructor, specifically looking for instances of the StringIO class. Then, with Forwardable, automatically forward all IO methods to the StringIO instance. Something like this:
require "stringio"
require "forwardable"

class MyIO < IO
   include Forwardable
   def initialize(arg)      
      if arg.kind_of?(StringIO)
         @io = arg
         delegate IO.instance_methods(false) => :@io
      else
         ...
      end
   end
end

That may be what I'll do for 0.3.3. However, I'll use my cleaned up version of Forwardable (which Matz has tentatively accepted) rather than the current version in the stdlib, which spews ugly warnings.

Read: Spreadsheet II: The Spreadsheet Strikes Back

Topic: Typo gets its own theme contest Previous Topic   Next Topic Topic: Ruby Code & Style

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use