Preparation for interview

8 minute read

My preparation for Ruby on Rails interview.

Mindmap

Summary of YouTube lectures of Ruby on Rails Courses

Lecture 1. Ubuntu install. Linux basics. RVM and Ruby install. Ruby Pros and Cons

Ruby is interpreted, dymamic, object-oriented programming language.

  • JIT — Just-in-Time compiling
  • MRI — Metz Ruby Interpreter
  • MJIT — MRI JIT
  • YARV — Yet Another Ruby VM
  • YARV-MJIT — modified MJIT
  • LLRB — LLVM Ruby JIT
  • LLVM — Low Level Virtual Machine
  • GCC — GNU Compilers Collection
  • JVM — Java virtual machine

RubyKaigi 2017, September 18..20, Hiroshima, Japan #rubykaigi

Ruby 3 and JIT: Where, When and How Fast?

REPL — Read Evaluate Play Loop — irb interactive Ruby

#!/usr/bin/env ruby
$ ruby —dump parse-tree

Book: “Agile Web Development with Rails 5”

Pipeline pattern

gem 'interactor'

Lecture 2. Ruby basics. Classes and modules

Variables

  • $global_variable
  • local_variable
  • @@class_variable
  • @instance_variable
  • CONSTANTS

.freeze

Functions

arr.reduce(&:*) # multiply all elements of array
def func(first:, last:, a: nil, b:, c: true)
end

Classes

Book: “Ruby under microscope”

Modules

Module Test
  include test # instance methods
  prepend 'test' # precedence over include
  extend test  # class methods
  # ...
end

Lecture 3. Classes and Modules. Ruby Object Model. Lambdas vs Procs vs Blocks

self — current recipient of the message

Block, Proc, Lambda

  1. Blocks — are not objects
  2. Blocks are faster — no need for object creation
  3. Proc, Lambda — are objects
  4. Proc is insensitive to the number of arguments (may pass more on call)
  5. Behavior on return:
    Anecdote:
    Proc and Lambda got into some sort of fight in a pub, and then
    Proc — flies off the pub
    Lambda — flies off the handle

To call lambda use .call, [], ===

case
  when ->(v) { |v| v % 2 == 0 }
end
a = Array.new(5) { |index| index }

Lecture 4. Metaprogramming

alias_method :old_plus, :+
# Pattern decorator
.send()
.define_method()
.undefine_method()
attr_reader
attr_writer
attr_accessor
.method_missing(name, *args, &block)
eval ‘’
.instance_eval ‘’
.class_eval ‘’

Lecture 5. Ruby Tips and Tricks. Array, Hash methods

arr.first(3) = arr.take(3)
arr.last() = arr.drop()
.each .reverse_each
.cycle
.sort_by(&:itself)
‘’.to_i(2)
.to_s(2)

Lecture 6. Gems. Ruby testing

Semantic versioning:
major.minor.patch

For example: ruby 2.4.1

Bundler

Minitest

RSpec

Timecop

stab — to substitute state,
mock — to substitute behaviour

Lecture 7. Web basics. Rack

TCP/IP stack

  • Application layer — HTTP, RTSP, FTP, DNS
  • Transport layer — TCP, UDP, SCTP, DCCP
  • Internet layer — Для TCP/IP это IP
  • Link layer — Ethernet, IEEE 802.11 WLAN, SLIP, Token Ring, ATM и MPLS

OSI stack

  • 7: application — HTTP, FTP, SMTP, RDP, SNMP, DHCP
  • 6: presentation — ASCII, EBCDIC, JPEG
  • 5: session — RPC, PAP
  • 4: transport — TCP, UDP, SCTP, PORTS
  • 3: network — IPv4, IPv6, IPsec, AppleTalk
  • 2: data link — PPP, IEEE 802.22, Ethernet, DSL, ARP, L2TP
  • 1: physical — USB, twisted pair, coaxial cable, fibre cable

IP header

IPheader

TCP header

TCPheaderCCNA Cisco

Rack

# config.ru
run ->(env) { [200, {}, ['Hello world']] }
$ rackup

Node.js Event loop

Node

Lecture 8. HTML, CSS, JS basics. Sinatra introduction

ERB

slim-lang.com

HTML2Slim

haml.info

CSS

SASS — Syntactically Awesome Stylesheets

JavaScript

CORS — cross-origin resource sharing

CoffeScript

Sinatra

Lecture 9. ActiveRecord Part 1, Part 2

ORM — Object-Relational Mapping

Patterns

  • Data mapper
  • Active record

gem ‘activerecord’

Migrations

create table :cars do |t|
  # …
  t.ref references :user, foreign_key: true, index: true
end
class User < ActiveRecord::Base
  has_many :cars, dependent: :destroy
end

class Car < ActiveRecord::Base
  belongs_to :user
end

Query

.find()
.find_by()
.where()
.order()
.limit()
.joins()
.pluck()
.destroy()
.save()
.update()

Callbacks

STI — Single Table Inheritance

Data Types

:primary_key
:string
:text
:integer
:bigint
:float
:decimal
:numeric
:datetime
:time
:date
:binary
:boolean

t.string 'tags', array: true
t.hstore 'settings'
t.json 'payload'
t.jsonb 'payload'
t.daterange 'duration'
t.column :status, :article_status
t.uuid :identifier
t.column :settings, "bit(8)"
t.inet 'ip'
t.cidr 'network'
t.macaddr 'address'
t.references

Lecture 10. Padrino

Lecture 11. Rails basics

Rails:

  • actioncable — to work with websocket
  • actionmailer — work with mail
  • actionpack —прослойка для работы приложения
  • actionview — helpers to work with view
  • activejob — to run background jobs
  • activemodel — validations for Active Record
  • activerecord — ORM
  • activesupport — i18n, timezone, minitest
  • railties —
  • sprockets-rails —

Rails composer

Lecture 12. Rails routing and controllers

CRUD — create, read, update, delete

routes shallow

params

cookies

session

flash

URI: schema://user:password@host:port/path?query#fragment

send_file

Lecture 13. Rails template engines. Assets pipeline. Rails form builders

erb — embedded ruby

respond_to do |format|
  format.html
  format.json do
    render json: @authors
  end

gem 'oj' — optimized JSON (with native extensions)

wkhtmltopdf

gem 'faker'

gem 'ryba'

Lecture 14. Rails background jobs. Rails action cable

gem 'sidekiq'
gem 'whenever'

# Action Cable
gem 'anycable'

Lecture 15. Deploying Rails Application

gem 'capistrano'

Setup Ruby On Rails on Ubuntu 16.04

Usefull resources to prepare for interview