Work with strings and symbols
Interpolate text, transform strings, and recognize symbols.
- 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.
1name = " ruby "
2puts name.strip.upcase
3status = :ready
4puts statusRUBY 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.
Format a name
Read a name, remove surrounding whitespace, convert it to uppercase, and print it.
- Lowercase name
- Mixed case
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…