Skip to content

Instantly share code, notes, and snippets.

@NigelThorne
Last active December 3, 2016 04:39
Show Gist options
  • Save NigelThorne/429b4fca6cf1a24fe368bfcb98a5c490 to your computer and use it in GitHub Desktop.
Save NigelThorne/429b4fca6cf1a24fe368bfcb98a5c490 to your computer and use it in GitHub Desktop.
def has_arg(arg)
ARGV.include? arg
end
text = ARGV[0]
lines = text.scan(/.{0,40}(?:\b|$)/).map{|l| l.strip }
lines = (lines[-1] == "" ? lines[0...-1] : lines)
longest = lines.map{|l| l.length}.max
lines.map!{|l| l+ (" " * (longest - l.length))}
def bubble(lines)
if (lines.count == 1)
if has_arg("--think")
"( #{lines[0]} )"
else
"< #{lines[0]} >"
end
else
borders = [ "/ $ \\",
"| $ |",
"\\ $ /"]
count = lines.count
lines.each.with_index.map{|line, index|
format = (index == count-1 ? 2 : (index == 0 ? 0 : 1) )
borders[format].gsub("$", line)
}.join("\n")
end
end
def eyes(args = ARGV)
moods = {
"--mad" => "oO",
"--wink" => "o-",
"--squint" => "><",
"--sleep" => "--",
"--dead" => "XX",
"--alarm" => "OO"
}
args.reverse.each{|arg| return moods[arg] if moods.has_key?(arg) }
"oo"
end
tongue = " "
tongue = "U" if has_arg "--mad"
link = "\\"
link = "o" if has_arg "--think"
puts """ #{ '_' * (longest+2)}
#{bubble lines}
#{ '-' * (longest+2)}
#{link} ^__^
#{link} (#{eyes})\\_______
(__)\\ )\\/\\
#{tongue} ||----w |
|| ||"""
@NigelThorne
Copy link
Author

NigelThorne commented Dec 3, 2016

Usage:

ruby cowsay.rb "Moo!" --mad

 ______
< Moo! >
 ------
        \   ^__^
         \  (oO)\_______
            (__)\       )\/\
             U  ||----w |
                ||     ||

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment