Skip to content

Instantly share code, notes, and snippets.

@UpperLEFTY
Created October 28, 2017 23:05
Show Gist options
  • Select an option

  • Save UpperLEFTY/57f3ad58c7a7f0577608eddcbdb5f6e2 to your computer and use it in GitHub Desktop.

Select an option

Save UpperLEFTY/57f3ad58c7a7f0577608eddcbdb5f6e2 to your computer and use it in GitHub Desktop.
Ruby on Rails Crash Course

Ruby

Basics

Create a Ruby Script

Create a file named hello.rb

puts "Hello!"

Run a Ruby Script

$ ruby hello.rb

Start the Interactive Ruby Shell

$ irb
1.9.3-p194 :001 >

Define a Method

def hello
  puts "Hello!"
end

Call a Method

hello

Define a Method with Argument

def hello(name)
  puts "Hello, #{name}!"
end

Call a Method with an Argument

hello("Brian")

Define a class

class Person

end

Instantiate a class

brian = Person.new

Define a Class Initializer

class Person
  def initialize
    puts "Initialize!"
  end
end

Define a Class Initializer with Arguments

class Person
  def initialize(name)
    puts "Initializing '#{name}'"
  end
end

Instantiate a class using an initializer

brian = Person.new("Brian")

Define an instance method

class Person
  def hello
    puts "Hello there!"
  end
end

Call an instance method

brian = Person.new("Brian")
brian.hello

Define an Instance Variable

Define Instance Variable Accessors

Using Arrays

Using Hashes

Intermediate

Extend a Class

class Employee < Person

end

Re-opening Classes

Define a Class Method

Call a Class Method

Blocks

Symbols

Define a Module

module Hello

end

Define a Module Method

module Hello
  def hello
    puts "Hello!"
  end
end

Call a Module Method

Hello::hello

Include a Module

include Hello

Include a module's methods in a class as instance methods

Include a module's methods in a class as class methods

Modules vs. Classes

Ruby Load Path

Require a Method or Class

Ruby Gems

Install a Gem

$ gem install pry

Ruby Version Manager

Install RVM

Install Ruby via RVM

Bundler

Install Bundler

Define a project's Gems

Install a projcet's Gems

Testing

RSpec

Libraries

Devise

Guard

Resources

Language, Gems & Tools

Documentation

Instructional Sites

Ruby

Rails

Books

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment