Installation, Tools and First Program

2.1 Installing Ruby

# macOS / Linux: use a version manager (don't use the system Ruby for development)
brew install rbenv ruby-build        # or: curl -fsSL https://rbenv.org/install.sh | bash
rbenv install 3.4.1
rbenv global 3.4.1

# Alternatives: asdf, mise, chruby + ruby-install, RVM
mise use -g ruby@3.4

# Windows: RubyInstaller (rubyinstaller.org) with DevKit (MSYS2), or WSL2

ruby -v
gem -v
bundle -v

2.2 Interactive Ruby

Run code directly: ruby -e 'puts "Hello"'. Run a file with ruby app.rb. Check syntax with ruby -c app.rb. Enable warnings with ruby -w app.rb.

irb                     # interactive REPL (syntax highlighting, autocompletion in modern irb)
irb(main):001> 2 + 3
=> 5
irb(main):002> "hello".upcase
=> "HELLO"
irb(main):003> help     # irb help, `show_doc String#upcase`, `ls`, `edit`

2.3 Hello, World

# hello.rb
puts "Hello, World!"

print "What's your name? "
name = gets.chomp           # read a line from stdin, remove the newline
puts "Nice to meet you, #{name}!"

2.4 Output Methods

Prints with a newline. Arrays print one element per line. Returns nil.

Prints without a newline Prints inspect output (developer-friendly) and returns the object (great for debugging) Pretty-prints complex structures printf / format $stdout.write, $stderr.puts, warn Low-level / error output

2.5 Editors and Tooling

VS Code with the Ruby LSP extension (Shopify): completion, go-to-definition, formatting, diagnostics. RubyMine (JetBrains) for a full IDE. Vim/Neovim with ruby-lsp/solargraph. Emacs with robe/enh-ruby-mode.

Documentation: ri String#split (offline docs), ruby-doc.org, docs.ruby-lang.org.