Um momento
0x20Lesson 3 of 6

Work with strings and symbols

Interpolate text, transform strings, and recognize symbols.

13 min 4-question quiz 1 code exercise
By the end of this lesson you can
  • Combine and transform Ruby strings.

Strings are sequences of characters. Double-quoted strings support interpolation and escape sequences. Methods such as upcase, downcase, and strip return useful string values. A symbol such as :status is an immutable named value often used as a hash key.

main.rb
1name = "  ruby  "
2puts name.strip.upcase
3status = :ready
4puts status
Output
RUBY
ready

Ruby method calls often read like plain language. A trailing ! in a method name commonly signals that it may modify an object, as in upcase!; without it, many string methods return a transformed copy.

Key takeaways

  • Combine and transform Ruby strings.

  • Ruby methods and blocks help express operations clearly.

  • Read each result and error message as feedback about your code.

Lesson quiz

4 questions · pass with 3 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: write Ruby

Write Ruby in the editor and run it against sample input. Your code is sent to Wandbox to run.

Exercise 1

Format a name

+25 XP

Read a name, remove surrounding whitespace, convert it to uppercase, and print it.

  • Lowercase name
  • Mixed case
main.rb
Loading editor…

Ruby runs through Wandbox, a free public service. Your source code and test input are sent to that service.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: