Skip to content

Instantly share code, notes, and snippets.

@tomohiro
Created September 22, 2011 05:03
Show Gist options
  • Save tomohiro/1234076 to your computer and use it in GitHub Desktop.
Save tomohiro/1234076 to your computer and use it in GitHub Desktop.
Start Ruby project

Start Ruby project

Plain project

$ mkdir awesome_project
$ cd awesome_project
$ cat << EOF > Gemfile
heredoc> source :rubygems
heredoc>
heredoc> gem 'sinatra'
heredoc> EOF
$ bundle install --path vendor/bundle
Fetching source index for http://rubygems.org/
Installing rack (1.3.3)
Installing tilt (1.3.3)
Installing sinatra (1.2.6)
Using bundler (1.0.18)
Your bundle is complete! It was installed into ./vendor/bundle
$ cat << EOF > app.rb
heredoc> require 'rubygems'
heredoc> require 'sinatra'
heredoc>
heredoc> get '/' do
heredoc>   'Hello, World!'
heredoc> end
heredoc> EOF
$ bundle exec ruby app.rb
== Sinatra/1.2.6 has taken the stage on 4567 for development with backup from WEBrick
[2011-09-22 13:50:55] INFO  WEBrick 1.3.1
[2011-09-22 13:50:55] INFO  ruby 1.9.2 (2011-07-09) [i686-linux]
[2011-09-22 13:50:55] INFO  WEBrick::HTTPServer#start: pid=13768 port=4567
$ curl localhost:4567
Hello, World!

Ruby Gem project

$ bundle gem awesome_gem
$ cd awesome_gem
$ vi awesome_gem.gemspec
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "awesome_gem/version"

Gem::Specification.new do |s|
  s.name        = "awesome_gem"
  s.version     = AwesomeGem::VERSION
  s.authors     = ["Tomohiro, TAIRA"]
  s.email       = ["[email protected]"]
  s.homepage    = ""
  s.summary     = %q{TODO: Write a gem summary}
  s.description = %q{TODO: Write a gem description}

  s.rubyforge_project = "awesome_gem"

  s.files         = `git ls-files`.split("\n")
  s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
  s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
  s.require_paths = ["lib"]

  s.add_runtime_dependency "sinatra"
end
$ bundle install --path vendor/bundle
Fetching source index for http://rubygems.org/
Installing rack (1.3.3)
Installing tilt (1.3.3)
Installing sinatra (1.2.6)
Using bundler (1.0.18)
Your bundle is complete! It was installed into ./vendor/bundle
$ vi lib/awesome_gem.rb
require "awesome_gem/version"
require 'sinatra'

module AwesomeGem
  get '/' do
    'Hello, World!'
  end
end
$ bundle exec ruby lib/awesome_gem.rb
== Sinatra/1.2.6 has taken the stage on 4567 for development with backup from WEBrick
[2011-09-22 14:30:32] INFO  WEBrick 1.3.1
[2011-09-22 14:30:32] INFO  ruby 1.9.2 (2011-07-09) [i686-linux]
[2011-09-22 14:30:32] INFO  WEBrick::HTTPServer#start: pid=19525 port=4567
$ curl localhost:4567
Hello, World!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment