This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CP1 | |
class Array | |
def sum_numbers | |
sum_numbers=0 | |
self.each do |num| | |
sum_numbers+=num | |
end | |
sum_numbers | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CP 1 | |
class Car | |
attr_accessor :make, :model, :year | |
def initialize(make, model, year) | |
@make, @model, @year = make, model, year | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CP1 | |
class Book | |
def title_and_author(title, author) | |
# set title to instance variable | |
# set author to instance variable | |
@title = title | |
@author = author | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CP1 | |
"hello world" | |
p "hello world" | |
p 4 | |
#CP2 Booleans, Symbols, Variables | |
p true | |
p false | |
my_string_variable = "hello world" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1CP NoMethodError | |
def hello(name) | |
"Hello #{name}" | |
end | |
# RSpec | |
describe "hello" do | |
it "should return 'Hello World' when passed 'World'" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CP1 | |
def new_array(a,b,c,d) | |
[a,b,c,d] | |
end | |
def first_and_last(a) | |
[a.first, a.last] | |
end |
NewerOlder