Coder Social home page Coder Social logo

hello-world-ruby-cb-gh-000's Introduction

Hello World

Overview

We're going to make a file that will print "Hello World!" to your terminal.

Objectives

  1. Create a new Ruby file.
  2. Write syntactically valid code to produce "Hello World!"
  3. Run a Ruby file.
  4. Run the Learn gem.
  5. Submit a Learn lab.

Instructions

Get started by clicking the Open button in Learn.

Creating a File

You will need to create a text file called hello_world.rb within the lab's directory. The .rb file extension is a common convention for specifying the language of the file - in this case, Ruby. To create this, in the Learn IDE's terminal type touch hello_world.rb. If that worked as expected, you should now see the file appear in the file browser. You can open this file by double clicking on it in the file browser or by typing atom hello_world.rb. You should now see an empty file open in your text editor, ready to be edited.

Writing Code

In the file hello_world.rb that you created, you need to write a single line of code that prints the string Hello World! to your terminal. To print in Ruby, you need to use the method puts which is short for "output string." And because Hello World! is a string, you need to surround your text with "".

File: hello_world.rb

puts "Hello World!"

Anytime you make changes to a file, such as the one you've just made, you need to save it so these changes are preserved. If you forget to save it before you run your tests, it will be tested against an empty document! Always remember to save it every time you make changes by selecting Save from the File menu.

Executing Your File

Execute this file by typing ruby hello_world.rb into your terminal and pressing enter. The ruby part of that command tells your computer to use the Ruby interpreter when reading and executing the code in your file. The second part of the command, hello_world.rb is the path to the file you want to run.

Note: be sure to save your file before trying to print, otherwise it will not work.

You should see:

$ ruby hello_world.rb
Hello World!

Running Learn

Confirm everything is working by running the learn command. You should see that all tests are passing (e.g. no red error text).

Note: When you write code, the case (uppercase/lowercase) of characters matters, and so your test will not pass unless you print "Hello World!" exactly.

Submitting Your Lab

Submit your solution by typing learn submit into your terminal, then click Next Lesson to move on.

Your adventure in Ruby has only just begun.

Hello World History

A small piece of coding history—a handwritten version of Hello World in C (an early programming language).

Hello World! Art

Hello World! by Brian Kernighan, from Artsy's Algorythm Auction based on a 1974 Bell Laboratories internal memorandum by Brian Kernighan, Programming in C: A Tutorial, which contains the first known version.

View Hello World on Learn.co and start learning to code for free.

hello-world-ruby-cb-gh-000's People

Contributors

aviflombaum avatar fislabstest avatar kthffmn avatar sammarcus avatar annjohn avatar dfenjves avatar matbalez avatar deniznida avatar fs-lms-test-bot avatar markedwardmurray avatar sirmatt avatar pczupil avatar sarogers avatar mjcalavano1 avatar mjl-fs-test-107 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.