Skip to content

Instantly share code, notes, and snippets.

@Sailias
Created June 14, 2013 15:41
Show Gist options
  • Save Sailias/5782845 to your computer and use it in GitHub Desktop.
Save Sailias/5782845 to your computer and use it in GitHub Desktop.
class ItemsController
def initialize
@items = []
1.upto(10) do |i|
@items << { id: i, name: "Item #{i}" }
end
# => GET /items
def index
@items.each do |item|
puts "id: #{item[:id]} - #{item[:name]}"
end
end
# => POST /items
def create
end
# => GET /items/:id
def show(index)
item = @items[index - 1]
puts "id: #{item[:id]} - #{item[:name]}"
end
# => DELETE /items/:id
def destroy
end
# => PUT /items/:id
def update
end
end
end
class Router
def initialize(url)
items = ItemsController.new
case url
when '/items'
items.index
when '/items/1'
items.show(1)
when '/items/2'
items.show(2)
else
items.index
end
end
end
http_method = ARGV[0]
url = ARGV[1]
Router.new(http_method, url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment