Ruby: Kein "Block" - Fehler

Dass ich immer ein "Nein block gegeben' Fehler beim übergeben Sie die Zeichenfolge, um die is_tut? Methode. Ich bin neu in Ruby und habe keine Ahnung was ich falsch mache. Jegliche Hilfe würde geschätzt werden.

class Tut
@@consonants = ["b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"]

  def is_tut? string
    if string =~ /^(([b-df-hj-np-z]ut)|([aeiou\s])|[[:punct:]])+$/i
      yield
    else
      false
    end
  end

  def self.to_tut string 
        string.each_char do |c|
            c += "ut" if @@consonants.find { |i| i == c.downcase }
            yield c
        end
    end

    def self.to_english string
        array = string.split //
        array.each do |c|
            if @@consonants.find { |i| i == c.downcase }
                array.shift
                array.shift
            end
            yield c
        end
    end


end

#Tut.to_tut( "Wow! Look at this get converted to Tut!" ) { |c| print c }
# should output : Wutowut! Lutookut atut tuthutisut gutetut cutonutvuteruttutedut tuto Tututut!

puts
puts

tut = Tut.to_tut( "Wow! Look at this get converted to Tut!" )
puts "from return: #{tut}"

puts

#Tut.to_tut( "Wutowut! Lutookut atut tuthutisut gutetut cutonutvuteruttutedut tuto Tututut!" ) { |c| print c }
# should outout : Wutowut! Lutookut atut tuthutisut gutetut cutonutvuteruttutedut tuto Tututut!
puts
puts

#tut = Tut.to_tut( "Wutowut! Lutookut atut tuthutisut gutetut cutonutvuteruttutedut tuto Tututut!" )
#puts "from return: #{tut}"

puts

#tut_string = ""
#Tut.to_tut( "I'm in tut but I want to be in english." ) { |c| tut_string += c }
#puts tut_string
# should output : I'mut inut tututut bututut I wutanuttut tuto bute inut enutgutlutisuthut.

puts

#Tut.to_english( tut_string ) { |c| print c }
# should output : I'm in tut but I want to be in english.
  • Nur als Tipp, mehr Ruby-ish Weg zu definieren, Ihre Konsonanten wäre: @@consonants = ('a' .. 'z').to_a - %w[a e i o u]
  • Ah, danke für den Tipp!
  • In Ruby, Einzug ist in der Regel zwei Räume.
  • Es blickt direkt in Textmate, finde es einfach nicht richtig einfügen.
InformationsquelleAutor James Titus | 2011-04-03
Schreibe einen Kommentar