Created
January 18, 2014 18:32
-
-
Save ph3nx/8494312 to your computer and use it in GitHub Desktop.
This Ruby program is a ruby function / method that prints a list / array in a rectangular frame of stars.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_to_frame list=[] | |
list = ["Hello", "World", "in", "a", "frame"] if list.empty? | |
longest = 0 | |
list.each do |element| | |
longest = element.length if longest < element.length | |
end | |
(0..longest+3).each do | |
print "*" | |
end | |
print "\n" | |
list.each do |el| | |
print "* " | |
print el | |
(0..longest-el.length).each do | |
print " " | |
end | |
print "*\n" | |
end | |
(0..longest+3).each do | |
print "*" | |
end | |
return | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment