Code Monkey home page Code Monkey logo

ruby-course's Introduction

Let's Use If/Else Statements to Find Out Ruby's Favorite Color

This repository will help you learn the fundamentals of If/Else statements in Ruby.

When completed, you'll have a program that asks for your favorite color, and replies with a specific response depending on your input.

ruby-course's People

Contributors

steven-galvin avatar

Watchers

James Cloos avatar 0x0FM avatar

ruby-course's Issues

Set up your environment

Hey there!

Today we will be learning the basics of Ruby. Ruby is a flexible and dynamic language, developed to feel natural and simple (some even call it beautiful💎). It is open source, and widely popular with the Rails framework.

Today, I'm going to guide you through your first Ruby project. First, we will write a program to output "Hello world" (as software developers are known to do). Then, we will learn some ruby methods to collect user input. Lastly, we will display different statements based on their input.

This is an interactive course, where you will be prompted to do something to finish each step. If it takes more than a few seconds for a response, try refreshing your browser.

Leave a comment with your name to continue

Run a 'hello world' program

Writing Our First Program: "Hello World!"

As I mentioned earlier, "Hello world" is a staple of web development. It's a program that every new developer will write at least a dozen times, and we're going to start by creating our own "Hello world" today.

To write "Hello world," let's start by navigating into our cloned repository by typing the following:

cd ruby-course

After navigating into our project folder, open up the file hello.rb and check out the code. There will be two lessons in this file, let's start by looking at lesson one.

In lesson one, you'll see the following line of code:

# puts "Hello World!"

What we have here is the Ruby method, puts, and the string, "Hello World!".

The # symbol turns our line of code into a comment which means that it won't be read when we run our program. It's there only for us to read. In order to turn a line of code into a comment in Ruby, the # must be placed at the start of a line of code.

We want this line to run, so let's delete the # and then save our file.

In programming, you'll often have pieces of code that need to be executed many times. Methods are a way to store that code in one place and then if you need to execute that code later, you can just call the method instead of writing out your block of code all over again.

Ruby comes with some default methods like our puts above, and these methods are available right away when you create Ruby projects. You can also create your own methods, though we aren't going to be getting into that in this tutorial.

A string is simply a line of text. They can be short like the title of this article, or long like an entire paragraph. The important thing to know is that strings are defined by enclosing text within single or double quotes.

The puts method tells our computer to print something to the screen. That something, in this case, is the string "Hello World!".

Leave a comment with correct letter that answers this question:

Which statement is true about Ruby methods?
a. Methods are lines of text.
b. You always need to write a method before using it.
c. They are pieces of code (default or custom) that can be reused.

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.