This file contains hidden or 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
def LetterChanges(str) | |
lower = "abcdefghijklmnopqrstuvwxyz" | |
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
vowels = "aeiou" | |
newString = [] | |
stringarray = str.chars | |
stringarray.each do |letter| | |
if letter.match(/^[[:alpha:]]$/) | |
index = lower.index(letter) |
This file contains hidden or 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
require_relative '../factorial.rb' | |
describe "Test the factorial function" do | |
it 'returns the right answer for 5' do | |
expect(factorial(5)).to eq(120) | |
end | |
it 'returns the right answer for 10' do | |
expect(factorial(10)).to eq(3628800) | |
end | |
it 'returns an error message for -5' do |
This file contains hidden or 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
def factorial(n) | |
if n <= 0 | |
puts "sorry I only compute the factorial for positive numbers" | |
return | |
else | |
@product = 1 | |
(1..n).each do |number| | |
@product *= number | |
end | |
return @product |
This file contains hidden or 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
def factorial_while(n) | |
if n <= 0 | |
puts "sorry I only compute the factorial for positive numbers" | |
return | |
else | |
idx = n | |
product = 1 | |
while idx > 1 | |
product *= idx | |
idx -= 1 |
This file contains hidden or 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
bundle install #installs all the gems you need to run the app | |
rake db:seed # seeds the database with movies, to see the movies you are seeding with navigate to rottenpotatoes/db/seeds.rb | |
rake db:test:prepare | |
rails s # Boot it up! |
This file contains hidden or 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
class MoviesController < ApplicationController | |
#NOTE: you can ignore show and index, we are only going to test the CRUD functions. | |
def movie_params | |
params.require(:movie).permit(:title, :rating, :description, :release_date) | |
end | |
def show | |
id = params[:id] # retrieve movie ID from URI route |
This file contains hidden or 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
rails generate rspec:install |
This file contains hidden or 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
rails generate rspec:controller movies |
This file contains hidden or 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
class MoviesController < ApplicationController | |
#some code | |
def create | |
@movie = Movie.create!(movie_params) | |
flash[:notice] = "#{@movie.title} was successfully created." | |
redirect_to movies_path | |
end |
This file contains hidden or 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
class MoviesController < ApplicationController | |
#some code | |
def show | |
id = params[:id] # retrieve movie ID from URI route | |
@movie = Movie.find(id) # look up movie by unique ID | |
# will render app/views/movies/show.<extension> by default | |
end |
OlderNewer