Ruby Notes – Ch1 Coding Test

The following are my notes from the chapter 1 introduction to programming.

There are three types of data in Ruby:

  1. Numbers
  2. Booleans – True or false
  3. Strings – Words or phrases

Ruby is case sensitive

puts can be called methods in Ruby

Integers = Whole #s (ex 42)

Floats = Fractional #s (e.g. 3.14)

Never write commas when writing integers. They will change everything.

Notes on Division

Ruby does not divide into integers. It returns whole #s

puts (9.0/2) | #returns 4.5

puts (9.fdive(2)) | #returns 4.5

Modulo n%m -> returns the remainder from division

Defining Variables

ian_loves = “guitar, wifey, surfing”

Variables must:

  • consist of letters or/and #s
  • first character must be lowerCase
  • no spaces (separate words w/ _ )

Gets Method

The gets method allows you to ask users to define variables
puts("Type in your name, please.")

This would return whatever the user entered

Gets for Strings and Integers

Converting Strings and Integers

  • to_i = to integer
  • to_s = to string

The Chomp Method

chomp makes it so a line break doesn’t happen behind each gets command. It seems like it’s used most of the time. For example:

puts("Type your name, please.")
name = gets
name = name.chomp
puts ("Hello" + name)

use gets.chomp rather than reassigning the variables.


Important Note: Feeling good about all of this. I can write program files using Atom and execute the files using terminal.

I went through the Codecademy command line class which was a critical step in understanding how to navigate and execute programs using just typing. This makes it so I can at least pretend to be like the guy in Mr. Robot.

It was today, November 20th, 2015 (these notes were copied her later) that I actually wrote and executed my first computer program. It was a game that said hello.
puts("Hello. What is your name, please?")
name = gets
name = name.chomp
puts("Hi " + name + ", it's nice to meet you.")

Screen Shot 2015-12-06 at 2.11.28 PM


That’s it

If you’d like to continue to follow along with these notes, I continue the study in my notes in chapter 2.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.