How to output any data using the $stdout method

Overview

In Ruby, $stdout represents the current standard output and a global variable. It means we can also use it to output data.

Syntax

$stdout << data
Syntax for $stdout in Ruby

Return value

This method returns the data printed to the console.

Code example

Let's look at the code below:

# create a variable
name = "Okwudili"
$stdout << "hello " << name
$stdout << "\nWelcome to Edpresso\n"
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources