[TxMt] Spreadsheets in Textmate

Charilaos Skiadas cskiadas at uchicago.edu
Mon Apr 24 03:53:19 UTC 2006


On Apr 23, 2006, at 4:59 PM, James Edward Gray II wrote:

> Another random idea from an obvious Ruby nut:
>
> set_data([...], ...)
>
> feels more natural as
>
> data[...] = ...
>
It does, but it won't quite work as it is. Right now the method data  
simply returns the array @rows, whose entries are each arrays, one  
corresponding to each data row.
Now, suppose @rows = [[1,2,3],[4,5,6]]
and you want to set the cell B3 to some value. Then you would try to do:
data[2,1]=7, but this would change @rows into [[1,2,3],[4,5,6],7]  
instead of [[1,2,3],[4,5,6],[nil,5,nil]]
set_data calls another method that makes sure to create any new rows  
necessary, and fill the required entries with "". So, in this case it  
would return [[1,2,3],[4,5,6],["",5,""]].
Actually, all those numbers will be strings because that's how the  
program deals with them. I also want to avoid having nils in the array.
Basically, I made an implementation choice to make sure the array is  
always "full". Maybe this was a mistake, but it made iterating over  
rows and columns easier without having to deal with nils.
Anyway, point is that this would require overriding "data" to somehow  
return something that could call this "fill rows" function based on  
the coordinates of the point [2,1] or whatever that is asked of you.

Btw, ideally I would like to be able to also say: data["B3"]=7  
instead. It would have to way for the next iteration, which will  
probably happen in two months.

I guess my problem is that I cannot define a method like:
def data[]=(row,col)

or can I?

> James Edward Gray II

Haris





More information about the textmate mailing list