Skip to content

Instantly share code, notes, and snippets.

@boscomonkey
Created November 30, 2011 05:18
Show Gist options
  • Save boscomonkey/1408137 to your computer and use it in GitHub Desktop.
Save boscomonkey/1408137 to your computer and use it in GitHub Desktop.
Ruby Quiz #14 - an evolving solution for SF Ruby Hack night
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
Numbers = [
[" - ",
"| |",
"| |",
"| |",
" - "],
[" | ",
" | ",
" | ",
" | ",
" | "],
["-- ",
" |",
" - ",
"| ",
" --"],
["-- ",
" |",
"-- ",
" |",
"-- "],
["| |",
"| |",
" - ",
" |",
" |"],
[" --",
"| ",
" - ",
" |",
"-- "],
[" --",
"| ",
" - ",
"| |",
" - "],
["-- ",
" |",
" |",
" |",
" |"],
[" - ",
"| |",
" - ",
"| |",
" - "],
[" - ",
"| |",
" - ",
" |",
"-- "]
]
def process msg # define function "process" w/ argument "msg"
scale = 1
(0..4).each {|layer_index| # step through layers 0 to 4
msg.each_char {|char| # for each character in argument
digit = char.to_i # convert char to integer
cell = Numbers[digit] # find the correct cell
layer = cell[layer_index] # peel off the ith layer of the cell
(0..scale).each {print layer}
# space needed to separate characters horizontally
print " "
} # end loop each char
# output a newline to wrap pointer to beginning of line
print "\n"
} # end loop each layer
end
process ARGV[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment