Skip to content

Instantly share code, notes, and snippets.

View msimonborg's full-sized avatar

m. simon borg msimonborg

  • vermont
View GitHub Profile
@msimonborg
msimonborg / deep_merge_benchmark.rb
Last active August 16, 2017 18:07
Benchmarking a reimplementation of Hash#deep_merge from the ActiveSupport library
require 'active_support'
require 'benchmark/ips'
class Hash
def new_deep_merge(other_hash, &block)
dup.new_deep_merge!(other_hash, &block)
end
def new_deep_merge!(other, &block)
merge!(other) do |key, old_val, new_val|
@msimonborg
msimonborg / deep_merge.rb
Created August 15, 2017 20:47
re-implementation of ActiveSupport's `Hash#deep_merge`
# frozen_string_literal: true
# Implemented in terms of Ruby's built-in ability to pass a block to handle duplicate keys in +merge+
class Hash
def deep_merge(other_hash, &block)
dup.deep_merge!(other_hash, &block)
end
def deep_merge!(other, &block)
merge!(other) do |_key, old_val, new_val|
@msimonborg
msimonborg / active_record_relation_send_bug.rb
Created July 17, 2017 23:33
When a scope method name collides with a Kernel method, calling with #send on an ActiveRecord::Relation doesn't work
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.