Skip to content

Instantly share code, notes, and snippets.

View ryanholm's full-sized avatar

Ryan Holm ryanholm

View GitHub Profile
@ryanholm
ryanholm / Commands
Last active August 29, 2015 14:03
Basic Commands Reference
host $ git clone https://github.com/rails/rails-dev-box.git
host $ cd rails-dev-box
host $ vagrant up
vagrant up - start Vagrant
vagrant ssh - log in to Vagrant
vagrant halt - shut down Vagrant
vagrant reload - restarts Vagrant
vagrant status - print the current status of Vagrant
vagrant suspend - suspends Vagrant, rather than shutting it down.
@ryanholm
ryanholm / Blocks
Last active August 29, 2015 14:02
BLOC Blocks
#CP1
def sort_by_length(sort_this_array)
sort_this_array.sort { |x,y| x.length <=> y.length}
end
def filter(filter_this_array)
filter_this_array.select { |num| num > 5 }
end
@ryanholm
ryanholm / Hashes
Last active August 29, 2015 14:02
BLOC Hashes
#CP1
class User
attr_accessor :name, :email, :bio, :age, :sex
def initialize(config = {})
@name = config[:name] || "n/a"
@email = config[:email] || "n/a"
@bio = config[:bio] || "n/a"
@age = config[:age] || "n/a"
@ryanholm
ryanholm / Loops
Last active August 29, 2015 14:02
BLOC Loops
#CP1
class Array
def sum_numbers
sum_numbers=0
self.each do |num|
sum_numbers+=num
end
sum_numbers
end
@ryanholm
ryanholm / Intro to Classes 2
Last active August 29, 2015 14:02
BLOC Intro to Classes 2
#CP 1
class Car
attr_accessor :make, :model, :year
def initialize(make, model, year)
@make, @model, @year = make, model, year
end
end
@ryanholm
ryanholm / Intro to Classes
Last active August 29, 2015 14:02
BLOC Intro to Classes
#CP1
class Book
def title_and_author(title, author)
# set title to instance variable
# set author to instance variable
@title = title
@author = author
end
@ryanholm
ryanholm / Ruby Syntax
Last active August 29, 2015 14:02
BLOC Ruby Syntax
#CP1
"hello world"
p "hello world"
p 4
#CP2 Booleans, Symbols, Variables
p true
p false
my_string_variable = "hello world"
@ryanholm
ryanholm / Reading RSpec Tests
Created June 13, 2014 05:29
BLOC Reading RSpec Tests
#CP1
def link_to(text,address)
"<a href='#{address}'>#{text}</a>"
end
# RSpec
describe "link_to" do
it "should return a valid link for Bloc" do
@ryanholm
ryanholm / Debugging Code
Last active August 29, 2015 14:02
BLOC Debugging Code
# 1CP NoMethodError
def hello(name)
"Hello #{name}"
end
# RSpec
describe "hello" do
it "should return 'Hello World' when passed 'World'" do
@ryanholm
ryanholm / Arrays
Last active August 29, 2015 14:02
BLOC Arrays
#CP1
def new_array(a,b,c,d)
[a,b,c,d]
end
def first_and_last(a)
[a.first, a.last]
end