Skip to content

Instantly share code, notes, and snippets.

@ken1flan

ken1flan/kittenizer.rb

Last active Nov 24, 2015
Embed
What would you like to do?
文字列の猫語化
class String
def kittenize
result = self
DICTIONARY.each do |word|
result.gsub!(word[0], word[1])
end
end
def kittenize!
DICTIONARY.each do |word|
self.gsub(word[0], word[1])
end
end
private
DICTIONARY = [
[/([^。])(。+)/, '\1にゃ\2'],
[/な/, "にゃ"],
[/ナ/, "ニャ"],
[/ま/, "みゃ"],
[/マ/, "ミャ"],
[/よう/, "にゃう"],
[/ヨウ/, "ニャウ"],
]
end
str = "てすと1。。"
puts str
result = str.kittenize!
puts str
puts result
str = "てすと2。。"
puts str
str.kittenize!
puts str
str = "てすと3。。"
puts str
str.gsub! /([^。])(。+)/, '\1にゃ\2'
puts str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.