Skip to content

Instantly share code, notes, and snippets.

View enumerable.rb
using Module.new {
refine Enumerable do
alias :orig_sum :sum
end
}
module Enumerable
def sum(...)
p method(:orig_sum)
end
View attribute_benchmark.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
View gist:7806543df5917b08bd598b9d884aa93a
```bash
brew install postgresql
pg_config
mkdir -p /usr/local/var/postgres
initdb /usr/local/var/postgres -E utf8
vi /usr/local/var/postgres/postgresql.conf
View gist:7ed4ee23a8c879d68bc7c7acc02f43f4
test_run_in_parallel_with_unmarshable_exception
test_run_in_parallel_with_unknown_object
% bin/test test/application/test_runner_test.rb -n test_run_in_parallel_with_unknown_object
View transaction_memory_usage.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
View undef.rb
puts RUBY_VERSION
module Rails
end
def Rails.root; :defined_root end
p defined?(Rails.root)
Rails.instance_eval { undef :root }
View assign_attributes_benchmark.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
View kwargs.rb
class Foo
def initialize(target)
@target = target
end
if RUBY_VERSION > "2.7"
def method_missing(method, *args, **kwargs, &block)
@target.send(method, *args, **kwargs, &block)
end
else
View lock.rb
# frozen_string_literal: true
require "mysql2"
def client
Mysql2::Client.new(
host: "localhost",
username: "root",
database: "test",
)
View environment.rb
# Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
ActiveRecord::SchemaDumper.ignore_tables << %r{
\A (?:
_ # initials _
| test_ # for testing