Skip to content

Instantly share code, notes, and snippets.

def hello
puts 'yo'
end
def hello
puts 'yo'
end
# app/controllers/api/v1/employees_controller.rb
class Api::V1::EmployeesController < ApplicationController
def index
@employees = Employee.all
end
#...
end
Rails.application.routes.draw do
namespace :api do
namespace :v1 do
get '/employees' => 'employees#index'
get '/employees/:id' => 'employees#show'
post '/employees' => 'employees#create'
patch '/employees/:id' => 'employees#update'
delete '/employees/:id' => 'employees#destroy'
end
# app/controllers/v1/employees_controller.rb
class V1::EmployeesController < ApplicationController
def index
@employees = Employee.all
end
#...
end
Rails.application.routes.draw do
namespace :v1 do
get '/employees' => 'employees#index'
get '/employees/:id' => 'employees#show'
post '/employees' => 'employees#create'
patch '/employees/:id' => 'employees#update'
delete '/employees/:id' => 'employees#destroy'
end
namespace :v2 do
@peterxjang
peterxjang / index.json.jbuilder
Last active April 5, 2016 01:19
jbuilder partial
json.array! @employees.each do |employee|
json.partial! 'employee.json.jbuilder', employee: employee
end
@data = {"query"=>{"count"=>1, "created"=>"2016-04-03T15:59:05Z", "lang"=>"en-US", "results"=>{"channel"=>{"units"=>{"distance"=>"mi", "pressure"=>"in", "speed"=>"mph", "temperature"=>"F"}, "title"=>"Yahoo! Weather - Nome, AK, US", "link"=>"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2460286/", "description"=>"Yahoo! Weather for Nome, AK, US", "language"=>"en-us", "lastBuildDate"=>"Sun, 03 Apr 2016 07:59 AM AKDT", "ttl"=>"60", "location"=>{"city"=>"Nome", "country"=>"United States", "region"=>" AK"}, "wind"=>{"chill"=>"14", "direction"=>"248", "speed"=>"11"}, "atmosphere"=>{"humidity"=>"80", "pressure"=>"1005.0", "rising"=>"0", "visibility"=>"16.1"}, "astronomy"=>{"sunrise"=>"8:8 am", "sunset"=>"10:3 pm"}, "image"=>{"title"=>"Yahoo! Weather", "width"=>"142", "height"=>"18", "link"=>"http://weather.yahoo.com", "url"=>"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"}, "item"=>{"title"=>"Conditions for Nome, AK, US at 06:00 AM AKDT", "la
# 1. Write out the Card and Deck classes to make the program work. The Deck class should hold a list of Card instances.
# 2. Change the program to use multiple choice questions. The Card class should be responsible for checking the answer.
# 3. CHALLENGE: Change the program to allow the user to retry once if they get the wrong answer.
# 4. CHALLENGE: Change the program to keep track of number right/wrong and give a score at the end.
# 5. CHALLENGE: Change the program to give the user the choice at the end of the game to retry the cards they got wrong.
# 6. CHALLENGE: Change the interface with better prompts, ASCII art, etc. Be as creative as you'd like!
class Card
end
AllCops:
DisabledByDefault: true
Layout/IndentationConsistency:
EnforcedStyle: indented_internal_methods
Layout/IndentationWidth:
Width: 2
Style/MethodDefParentheses: