Speed up development with full-stack environments for every branch.

Learn More

Say happy Valentines Day with a heart in Ruby [vday]

Forked from Basic Ruby Example.

96 Runs 108 Views 16 Copies

Tell that special someone happy Valentines Day in Ruby

Saved

Saved

AnandPatel 55

AnandPatel
published 3 years ago

name = "Nancy";

l=->a,b=28,c=1{puts (("Love"*a).center(b))*c};
l.call(2,14,2);
l.call(3,14,2);
[7,7,7,6,5,4,3,2,1].map{|x|l.call(x)};

puts "\n    Happy Valentines Day";

# We need to center the name so add some whitespace logic here
whiteSpaceNeedTaken = 28-name.length;
# find out how much we need on each side
splitWhiteSpace = whiteSpaceNeedTaken/2;
leftSpace = splitWhiteSpace;
puts " " * leftSpace + name;
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).