Skip to content

Instantly share code, notes, and snippets.

Ruby Method Lookup Algorithm

class Human
end

class Person < Human
end

person = Person.new

Pull Request Description Template

Overview

  • This gist contains a PR description template.

  • Copy its content to your PRs and replace all TODOs with useful information (Scroll to the bottom to see its preview).

  • Depending on the complexity of the PR some sections may be completely skipped. Make a decision based on your experience.

require "byebug" if (defined? ::Rails::Console)
(require "#{`bundle info byebug --path`.chomp}/lib/byebug.rb"; byebug) if (defined? ::Rails::Console)
(require `gem which byebug`.chomp; byebug) if (defined? ::Rails::Console)
Status 🚧
Tags code-review, principles

General Code Review Principles

  • Always try to get familiar with the problem domain at least for some adequate time period before asking questions (make an initial investigation, check existing codebase, find confluence pages, read the docs, prepare a list of concrete questions, etc).

  • Try to predict possible edge cases by yourself (you don't need to implement all of them, but you should be aware of the probability).

Format and highlight HTML from Ruby

Usage

Copy monkey_patch.rb or util.rb content into your project.

API

string.to_pretty_html

Convenient Service Diagrams

Just download the HTML page you like and open it in your browser.

Here is an example using cURL (please, scroll horizontally to see the full command, I could place rm -rf * in the end 🤯):

curl https://gist.githubusercontent.com/marian13/504631acfbfbeecc2503c0cd7614ca9c/raw/d0368d93090aea88323a184e7ef43b10db24f667/convenient_service_diagrams_method_middlewares_sequence_diagram.html -o diagram.html && open diagram.html

Not predictable equal? behaviour

  • Try to guess what is the return value of question.equal?("hurting yourself") in test_1.rb.

  • true? Are you sure?

  • Run test_1.rb

ruby test_1.rb

Module#include has incompatibilities between Ruby 2 and 3

Try to run the following example:

puts RUBY_VERSION

module IncludeModule
  def foo
 "foo from `IncludeModule`"

Do not accidentally create global methods in Ruby

Here is an example:

do_not_accidentally_create_global_methods_in_ruby_2_7

It is common to make such mistake in spec_helper, Rakefile, etc.

A proof that unless condition_1 && condition_2 is the same as if !condition_1 || !condition_2.

  • Create a file.

    touch test.rb
  • Paste the following content inside of it.