asf

Ruby code posted by asdf
created at 15 Sep 18:38

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def output_box str, charh, charv, charc
  stra = (str + "\n ").split("\n")
  stra.pop
   strl = stra.max_by{|a| a.length}.length
  i = 0
  puts charc + charh * (strl + 2) + charc
  while i < stra.length do
    print "#{charv} "
    yield stra[i], strl
    puts " #{charv}"
    i += 1
  end
  puts charc + charh * (strl + 2) + charc
end

def fancy_puts_line str
  output_box(str, "-", "|", "+") {|a, b| print a + " " * (b - a.length)}
end

def fancy_puts str
  output_box(str, "#", "#", "#") {|a, b| print a + " " * (b - a.length)}
end

def fancy_puts_line_center str
  output_box(str, "-", "|", "+") {|a, b| print a.center b}
end

def fancy_puts_center str
  output_box(str, "#", "#", "#") {|a, b| print a.center b}
end


fancy_puts """! Critical Error !
System resources low!"""

fancy_puts_line_center """

Five syllables here
Seven more syllables there
Are you happy now?

"""
902 Bytes in 7 ms with coderay