Skip to content

Instantly share code, notes, and snippets.

@ph3nx
Created January 18, 2014 18:32
Show Gist options
  • Save ph3nx/8494312 to your computer and use it in GitHub Desktop.
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.
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