openskills.info
Ruby Fundamentals logoCourse Preview

Ruby Fundamentals

Ruby is an object-oriented, dynamically typed programming language. You write expressions, send messages to objects, organize code into methods, classes, and modules, and distribute reusable code as gems managed by Bundler.

itProgramming languages

Ruby Fundamentals

Ruby is a general-purpose programming language in which every value is an object and most behavior is expressed by sending a method call to an object. A Ruby implementation reads source code, evaluates expressions, creates and manipulates objects, and performs effects such as writing a file or making a network request.

source file → parser → Ruby execution → objects + method calls → effects

The Ruby language and a particular implementation are different things. CRuby is the reference implementation commonly called Ruby, while JRuby and TruffleRuby run the language on different runtime systems. Code that relies on documented language behavior travels more easily than code coupled to one implementation's internals.

Everything is an object

Integers, strings, arrays, hashes, classes, and nil are objects. A method call names a receiver and a method:

name = "Ada"
name.upcase

name is a local variable that refers to a String object. upcase is a method sent to that object. The expression returns a new uppercase string; it does not change name. Ruby convention uses a bang suffix for a method that has a more dangerous counterpart. In core classes, that often means the bang method mutates its receiver, but read the API rather than treating the suffix as a language guarantee.

name.upcase!  # changes the String object that name refers to

Assignment changes what a local variable refers to. Mutation changes the object itself. That distinction matters when two variables refer to one mutable object.

tags = ["ruby"]
alias_tags = tags
alias_tags << "language"

Both variables now observe two entries because << mutated one Array. Use dup, clone, or a purpose-built copy when separate ownership is required. A shallow copy does not duplicate objects nested inside a collection.

Continue the course

This section is part of the paid course.

See pricing to subscribe, or log in if you already have access.

Where this skill leads

Relevant careers

See how this topic contributes to broader role-level skill maps.

Sources