DEV Community

Jr Carreiro
Jr Carreiro

Posted on

🔵 Chapter 02 – Ruby Language Fundamentals (Line by Line for Absolute Beginners)

Welcome to Chapter 02 of my learning journey through scripting and offensive security.

I’m not just learning to code — I’m learning to build, document, and explain.
This series is based on Hacking with Go, but reimagined in Ruby and Swift, with step-by-step examples and real-world analogies to help anyone understand — even if you’ve never written a single line of code.


🧱 What we’ll cover in this chapter:

  • 📦 Variables (how to store information)
  • 🔁 Loops (how to repeat actions)
  • 🔀 Conditionals (how to make decisions)
  • 🧠 Functions (how to reuse logic)
  • 💬 Input/Output (how to talk to the user)

💡 Variables – Giving names to values

name = "Alice"age = 30
Enter fullscreen mode Exit fullscreen mode

🧠 Explanation

We’re storing data in memory using variables.

  • name holds the string "Alice"
  • age holds the number 30

Think of variables like stickers you put on boxes — the name tells you what’s inside.


🔁 Loops – Repeating things automatically

3.times do  puts "Knock knock!"end
Enter fullscreen mode Exit fullscreen mode

🧠 Explanation

  • 3.times runs the block three times
  • puts prints the message

This is like telling a kid: “Say ‘knock knock!’ three times” — and they’ll do it without question.


🔀 Conditionals – Making decisions

password = "swordfish"if password == "swordfish"  puts "Access granted!"else  puts "Access denied!"end
Enter fullscreen mode Exit fullscreen mode

🧠 Explanation

We check a condition:
If the password matches, we let the person in. Otherwise, we block them.

It’s like checking someone’s ID before opening the door.


🧠 Methods – Reusable blocks of logic

def greet(name)
  "Hello, #{name}!"endputs greet("Alice")
Enter fullscreen mode Exit fullscreen mode

🧠 Explanation

We’re defining a method (like a mini-program) that:

  • Takes one input: name
  • Returns a message using string interpolation

Calling greet("Alice") is like pushing a button labeled “Say hello to Alice.”


💬 User Input – Interacting with people

print "What's your name? "name = gets.chompputs "Welcome, #{name}!"
Enter fullscreen mode Exit fullscreen mode

🧠 Explanation

  • print shows a prompt without a newline
  • gets waits for input from the user
  • chomp removes the trailing newline

This is how Ruby talks to the user — and listens back.


🧠 Final Recap

📦 Variables → Store information with names
🔁 Loops → Repeat things automatically
🔀 Conditionals → Make decisions
🧠 Methods → Reuse blocks of logic
💬 Input/Output → Talk to the user


✅ You’ve learned the building blocks

This chapter gave you everything you need to start writing real scripts.

Next up: we’ll dive into useful packages and Ruby gems to do powerful things like parsing files, automating tasks, and working with the web.

📫 About the Author

[Júnior Carreiro]
🔐 Mobile AppSec | iOS Security | Reverse Engineering
📍 Let's connect: [GitHub] · [Linkedin]

Top comments (0)