Skip to content

Instantly share code, notes, and snippets.

@acook
Created March 22, 2013 19:02
Show Gist options
  • Save acook/5223850 to your computer and use it in GitHub Desktop.
Save acook/5223850 to your computer and use it in GitHub Desktop.
PigLatin Translator!
#!/usr/bin/env ruby
# Translates a text file to Pig Latin!
class PigLatin
def initialize filename = nil
@filename = filename
end
attr :filename
def translate!
ilefay filename
end
def ilefay file
lines = String.new
IO.foreach file do |line|
lines << inelay(line)
end
lines
end
def inelay line
line.split(' ').map do |word|
ordway word
end.join ' '
end
def ordway word
alpha = word.match(/[a-zA-Z]+/).to_s
"#{alpha[1..-1]}#{alpha[0]}ay"
end
end
def self.usage
puts "usage : #{$0} path/to/file.txt"
end
translator = PigLatin.new ARGV.first || usage
puts translator.translate!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment