w3resource

Ruby String Exercises: Draw a string as bold or italic text


Write a Ruby program to draw a string as bold or italic text.

Ruby String Exercises: Draw a string as bold or italic text

Ruby Code:

def make_tags(tag, word)
    "<#{tag}> #{word} </#{tag}>"
end
print make_tags("i", "Ruby")
print "\n",make_tags("b", "Ruby")

Output:

<i> Ruby </i>
<b> Ruby </b>

Flowchart:

Flowchart: Draw a string as bold or italic text

Go to:


PREV : Ruby Array Exercises
NEXT : Write a Ruby program to insert a string of length 2 to an another string where the first string will be in the middle of the second string.

Ruby Code Editor:



Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.