Skip to content

Instantly share code, notes, and snippets.

@ken1flan
Last active November 24, 2015 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ken1flan/63dd8e0577b5ca075a53 to your computer and use it in GitHub Desktop.
Save ken1flan/63dd8e0577b5ca075a53 to your computer and use it in GitHub Desktop.
文字列の猫語化
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