DEV Community

Taylor D Jones
Taylor D Jones

Posted on

1

Ruby String Methods

Today I was working mainly with Ruby strings. It still surprises me how many of these methods cross over into Javascript, although they have different names. Let's explore some of the essentials Ruby string methods and what they do:

.reverse
This method returns a new string with the characters in reverse order. For example:
Ruby's .reverse method example

.upcase
returns a new string with all characters converted to uppercase. Example:
.upcase method example

.downcase
returns a new string with all characters converted to lowercase. Example:
.downcase method example

.swapcase
returns a new string with uppercase characters converted to lowercase and vice versa. Example:
I.swapcase method example

.capitalize
This method returns a new string with the first character converted to uppercase and the rest to lowercase. Example:
.capitalize method example

.strip
returns a new string with leading and trailing whitespace removed. For example:
.strip method example

.gsub
returns used for global substitution, replacing all occurrences of a pattern in a string with another string. For example:
.gsub method example

Until next time, happy coding!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay