Halving a string

Hi Chris,

I have a vacuum fluorescent display in my office, and I’ve been
messing around with it. Now that I’ve figured out how to communicate
with the serial connection it’s time for some fun.

aside the string hackery, will the comunication be done using ruby? :stuck_out_tongue_winking_eye:

On Feb 2, 11:32 am, “Tiago P.” [email protected] wrote:

Hi Chris,

I have a vacuum fluorescent display in my office, and I’ve been
messing around with it. Now that I’ve figured out how to communicate
with the serial connection it’s time for some fun.

aside the string hackery, will the comunication be done using ruby? :stuck_out_tongue_winking_eye:

[snip]

Mine will be. The code for handling the communication is ugly (the
win32api pretty much guarantees that), but I’ve wrapped it in a module
so I never have to look at it again (hopefully). I’m using the display
as stdout for a couple of little maintenance scripts, too.

Otherwise, there’s been some great solutions here. Thanks everyone.

On Feb 2, 2007, at 12:52 PM, Trans wrote:

class String
middle ||= self.length/2

T.

That sounded good to me and so I did that and added support for
negative (from the end) offsets, too. And like String#[], it returns
nil if the desired cleavage position is outside the string.

def cleave(middle=nil)
middle ||= self.length/2
return nil unless (-self.length … self.length).include?(middle)

 middle += self.length if middle < 0

 #...

end

-Rob

P.S. If anyone wants the full thing (with the new tests), email me
directly.

Rob B. http://agileconsultingllc.com
[email protected]