ruby 红宝石句子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 红宝石句子相关的知识,希望对你有一定的参考价值。

class Word
    def initialize(word)
        @word = word
    end
    def append(str)
        @word = @word << str
        return @word
    end
    def get
        return @word
    end
    def setword(str)
        @word = str
    end
    def tag(str)
        @tag = str
    end
end

class Sentence
    def initialize(statement)
        @sentence = statement
        statement = statement.chop
        statement = statement.downcase
        lst = statement.split(" ")
        @words = []
        for elem in lst
            @words << Word.new(elem)
        end
    end
    def addword(str)
        @words << Word.new(str)
    end
    def set_word(i, other)
        @words[i].setword(other)
    end
    def [](i)
        @words[i].get()
    end
    
    def length
        @words.length
    end
    def addpunc(symbol)
        @words[self.length-1].setword(@words[self.length-1].get << symbol)
    end
    def checkforword(str)
        for elem in @words
            if elem.get == str
                return true
            end
        end
        return false
    end
end

class Paragraph
    def initialize(text)
        @paragraph = text
        @sentence_box = []
        count = 0
        until text.length == 0 do
            if text[count] == "."
               @sentence_box << Sentence.new(text[0..count])
               text = self.cutstring(text, 0, count)
               count = 0
            elsif text[count] == "?"
               @sentence_box << Sentence.new(text[0..count])
               text = self.cutstring(text, 0, count)
               count = 0
            elsif text[count] == "!"
               @sentence_box << Sentence.new(text[0..count])
               text = self.cutstring(text, 0, count)
               count = 0
            else
                count += 1
            end
        end
    end
    def cutstring(str, start, stop)
        str[start..stop] = ""
        return str
    end
    def [](i)
        @sentence_box[i]
    end
    def checkforword(str)
        for sentence in @sentence_box
            if sentence.checkforword(str) == true
                return true
            end
        end
        return false
    end
end

以上是关于ruby 红宝石句子的主要内容,如果未能解决你的问题,请参考以下文章

爱情之石—红宝石(Ruby)

科普红宝石 Ruby

红宝石ruby

红宝石Ruby

ruby rails3创建自己的红宝石宝石

ruby,红宝石戒指到货