Problems porting from Python to Ruby

I have a neat little script in python that I would like to port to Ruby and I think it's highlighting my noobishness at Ruby. I'm getting the error that there is an unexpected END statement, but I don't see how this can be so. Perhaps there is a keyword that requires an END or something that doesn't want an END that I forgot about. Here is all of the code leading up to the offending line Offending line is commented.

    require base64
    require base32
rescue LoadError
    puts "etext requires base32. use 'gem install --remote base32' and try again"

# Get a string from a text file from disk
filename = ARGV.first
textFile =
text =

mailType = "text only" # set the default mailType

#cut the email up by sections
textList1 = text.split(/\n\n/)
header = textList1[0]

if header.match (/MIME-Version/)
    mailType = "MIME"

#If mail has no attachments, parse as text-only. This is the class that does this
class TextOnlyMailParser

    def initialize(textList)
        a = 1
        body = ""
        header = textList[0]
        @parsedEmail =
        while a < textList.count
            body += ('\n' + textList[a] + '\n')
            a += 1
        @parsedEmail.body = body

def separate(text,boundary = nil)
    # returns list of strings and lists containing all of the parts of the email
    if !boundary #look in the email for "boundary= X"
        text.scan(/(?<=boundary=).*/) do |bound|
            textList = recursiveSplit(text,bound)
        return textList
    if boundary 
        textList = recursiveSplit(text,boundary)

def recursiveSplit(chunk,boundary)
    if chunk.is_a? String
        searchString = "--" + boundary
        ar = cunk.split(searchString)
        return ar
    elsif chunk.is_a? Array
        chunk do |bit|

class MIMEParser
    def initialize(textList)
        @textList = textList
        @nestedItems = []
        newItem =
        newItem.value = @textList[0]
        newItem.contentType = "Header"
        #setup parsed email
        @parsedEmail =

        def checkForContentSpecial(item)
        match = item.value.match (/Content-Disposition: attachment/)
        if match
            filename = item.value.match (/(?<=filename=").+(?=")/)
            encoding = item.value.match (/(?<=Content-Transfer-Encoding: ).+/)
            data = item.value.match (/(?<=\n\n).*(?=(\n--)|(--))/m)
            dataGroup = data.split(/\n/)
            dataString = ''
            i = 0
            while i < dataGroup.count
                dataString += dataGroup[i]
                i ++
            end #<-----THIS IS THE OFFENDING LINE


Your issue is the i ++ line, Ruby does not have a post or pre increment/decrement operators and the line is failing to parse. I can't personally account as to why i++ evaluates in IRB but i ++ does not perform any action.

Instead replace your ++ operators with += 1 making that last while:

while i < dataGroup.count
  dataString += dataGroup[i]
  i += 1

But also think about the ruby way, if you're just adding that to a string why not do a dataString = dataGroup.join instead of looping over with a while construct?

Need Your Help

how to map wgs84 coordinates to sql server b-tree index (w/o using built in spatial indexes)

sql-server geometry coordinate-systems wgs84 tessellation

I would like to be able to map geographic points from WGS84, I believe, formatted for ms sql server, to the set of cells it would touch if the same coordinate pair were to be tessallated into an sql

Printing messages to console from C++ DLL


I have an application which uses C# for front end and C++ DLL for the logic part. I would want to print error messages on console screen from my C++ DLL even when the C# GUI is present. Please let me

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.