HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to RubyVariablesData TypesOperatorsStringsArraysHash (Dictionary)Conditions (if / else)LoopsMethods (def)Classes
REFERENCE
📖 Overview
🖥️ Output & Input
📦 Variables
🔢 Numbers & Math
✍️ String
.lengthupcase / downcase / capitalizestrip / chompgsub / subsplit / joininclude? / index
📋 Array
🗂️ Hash (Dictionary)
🔁 Condition & Loop
🧩 Method & Class
Ruby›REFERENCE›String
✍️

String

String methods: length, transformation, replacement, splitting.

CommandDescription
.lengthReturns the number of characters.
upcase / downcase / capitalizeChanges the letter case.
strip / chompCleans up whitespace.
gsub / subReplaces a part of the string.
split / joinSplits text into an array / joins an array into text.
include? / indexIs a substring present / where is it?

.length

Try it yourself →

Returns the number of characters.

Syntax

text.length

Description

Returns the length of the string (same as .size).

Example

puts "merhaba".length

Expected output

7

When to use?

Length check.

upcase / downcase / capitalize

Try it yourself →

Changes the letter case.

Syntax

text.upcase

Description

upcase makes uppercase, downcase lowercase, capitalize capitalizes the first letter. Returns a new text.

Example

puts "ada".upcase
puts "ADA".downcase
puts "ada lovelace".capitalize

Expected output

ADA
ada
Ada lovelace

When to use?

Comparison, representation.

strip / chomp

Try it yourself →

Cleans up whitespace.

Syntax

text.strip

Description

strip removes leading/trailing spaces, chomp removes the trailing newline.

Example

puts "   space   ".strip

Expected output

space

When to use?

Input sanitization.

gsub / sub

Try it yourself →

Replaces a part of the string.

Syntax

text.gsub(old, new)

Description

gsub replaces all matches, sub replaces only the first one.

Example

puts "leo leo".gsub("leo", "emma")

Expected output

emma emma

When to use?

Text cleaning, templating.

split / join

Try it yourself →

Splits text into an array / joins an array into text.

Syntax

text.split(separator) · arr.join(separator)

Description

split breaks into parts (arr); join does the reverse.

Example

p "a,b,c".split(",")
puts ["x", "y", "z"].join("-")

Expected output

["a", "b", "c"]
x-y-z

When to use?

CSV parsing, arr↔text.

include? / index

Try it yourself →

Is a substring present / where is it?

Syntax

text.include?(part)

Description

include? returns true/false, index returns the position (or nil if missing). Methods ending with ? return true/false.

Example

puts "education".include?("cat")
puts "merhaba".index("hab")

Expected output

true
3

When to use?

Search, content check.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code