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 to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources