This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark/ips" | |
def foo(seq, kw) | |
end | |
def fast | |
kw = { a: 1, b: 2, c: 3 } | |
foo(1, kw) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required.' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'rom' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Entities | |
class User < ROM::Struct | |
def name | |
[first_name, last_name].join(' ') | |
end | |
end | |
end | |
class Users < ROM::Relation[:sql] | |
schema do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < Dry::Struct | |
MissingAttribute = Class.new(NameError) | |
def name | |
[first_name, last_name].join(' ') | |
end | |
attribute :name, Dry::Types['strict.string'] | |
attribute :first_name, Dry::Types['strict.string'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'dry-auto_inject' | |
gem 'dry-transaction' | |
gem 'dry-container', git: 'https://github.com/dry-rb/dry-container' | |
end | |
class Container |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Maybe | |
class Some < Maybe | |
end | |
class None | |
end | |
end | |
class Result | |
class Success < Result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Templates < ROM::Relation[:sql] | |
schema do | |
attribute :possible_resolution_ids, Types::PG::Array('bigint') | |
associations do | |
has_many :resolutions, | |
as: :possible_resolutions, | |
relation: :resolutions, | |
view: :for_possible_resolutions_in_templates, | |
foreign_key: :template_id, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search_tags(query, tags) | |
tag_queries = tags.map { |t| pattern(t) } | |
query.where { tag_queries.reduce(`false`) { |acc, q| acc | array_to_string(self.tags, ',').ilike(q) } } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def self.===(obj) | |
true | |
end | |
end | |
begin | |
1 / 0 | |
rescue Foo | |
puts 'Rescued!' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Matcher | |
def self.[](pattern) | |
Class.new do | |
define_singleton_method(:===) { |exc| pattern === exc.message } | |
end | |
end | |
end | |
begin | |
1 / 0 |