Files
one-knowledge/github-knowledge/ruby.md
T

2.1 KiB

title, created, updated, type, tags, external
title created updated type tags external
Ruby 2018-06-14 2018-06-14 summary
tech
reference
https://github.com/wahyd4/knowledge/blob/master/categories/ruby.md

Objects inheritances

objects

Background jobs

  • Resque
    • Single threaded process
  • Delayed Job
    • Single process
  • Sidekiq
    • Redis and multiple threaded process
        while(!empty(queue)) {
               = get(queue); //从任务队列中取一个(涉及加锁等)
              q->callback(); //执行该任务
          }
      

Test

  • Unit Test
    • Mini Test
    • RSpec
  • Browser Test
    • Capybara
    • Cucumber
  • Mock
    • Mocha

Auth

  • OmniAuth
  • Devise

Web Server

  • Thin
  • Unicorn
  • Puma
  • Passenger
  • Pow

Language

  • Syntax
    • lambda
    • yield
    • respond_to
    • send
    • <=>
      • return 1,0, -1
      • before array
        • splat operator: split an array into a list of arguments
    • array << obj
      • append obj to new arry
  • block {} do end
    • Block is not object
    • use yield pass block
  • Proc
    • Proc is object
    • greeting = Proc.new { puts "hello, world" } greeting.call
  • Module
    • Can't be new
    • include
    • can't extend
  • Class

Code analysis

  • Rubocop

GC

  • Minor GC
  • Major GC
  • GC.stat

Bundler

Use groups in bundler

# These gems are in the :default group
gem 'nokogiri'
gem 'sinatra'

gem 'wirble', :group => :development

group :test do
  gem 'faker'
  gem 'rspec'
end

group :test, :development do
  gem 'capybara'
  gem 'rspec-rails'
end

gem 'cucumber', :group => [:cucumber, :test]

when you install bundles, you can do

bundle install --without test development

Web frameworks

Sintra

Ruby on Rails

How Rails application works

Rails flow

- ORM
	- Active record
	- Mongoid
- Websocket
- Assets pipeline
- Rails console

Gem mirrors