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 'json-schema' | |
| text = '{"uuid":"3ea8fd89-232f-4ed1-90b5-743da173cd7d","name":"FIRM"}' | |
| schema = ' | |
| { | |
| "$schema": "http://json-schema.org/draft-04/schema#", | |
| "type": "object", |
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 "rom" | |
| ROM.setup :memory | |
| class Users < ROM::Relation[:memory] | |
| register_as :users | |
| end | |
| class Tasks < ROM::Relation[:memory] | |
| register_as :tasks | |
| 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
| Calculating ------------------------------------- | |
| method 56.995k i/100ms | |
| proc 49.213k i/100ms | |
| proc new 57.562k i/100ms | |
| ------------------------------------------------- | |
| method 1.797M (±10.7%) i/s - 8.891M | |
| proc 1.522M (± 8.3%) i/s - 7.579M | |
| proc new 1.867M (± 7.9%) i/s - 9.267M | |
| Comparison: |
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 'equalizer' | |
| module Checkproc | |
| InvalidValueError = Class.new(StandardError) { include Equalizer.new(:message) } | |
| class Composite | |
| attr_reader :left | |
| attr_reader :right | |
| def initialize(left, right) |
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
| # identity | |
| id = -> v { v } | |
| # composition | |
| composition = -> g, f { -> v { g[f[v]] } } | |
| # testing for id | |
| g = -> v { v * 2 } | |
| composition(g, id)[3] == g[3] # true | |
| composition(id, g)[3] == g[3] # true |
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 'fiddle' | |
| A = Class.new | |
| B = Class.new | |
| C = Class.new A | |
| p C.superclass # => A | |
| (Fiddle::Pointer[Fiddle.dlwrap C] + 16)[0, 8] = Fiddle::Pointer[Fiddle.dlwrap B].ref | |
| p C.superclass # => B |
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 "rspec" | |
| require "mustermann" | |
| # Checks whether client condition has received given request | |
| # | |
| # @example | |
| # allow(client) | |
| # .to receive_request(:get, "example.com/users/:id/bills") | |
| # .and_return({ id: 1, price: 100, currency: "RUR" }) | |
| # |
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 "rspec" | |
| require "mustermann" | |
| require "delegate" | |
| # Gem-speficic RSpec mocks and expectations | |
| # | |
| # @example | |
| # allow(client) | |
| # .to receive_request(:get, '/users/1') | |
| # .where { |req| req[:query].include? "auth" => "foobar" } |
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
| # Happy birthday to you... | |
| # | |
| # @example | |
| # dates = MartianAnniversaries.from '2015-01-01' | |
| # dates.take(2) | |
| # # => ['2016-11-17', '2018-10-05'] | |
| # | |
| class MartianAnniversaries | |
| include Enumerable |
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 'reform' | |
| require 'reform/form/coercion' | |
| require 'hashie/mash' | |
| module Reform | |
| module DryTypes | |
| def property(name, type: nil, **options, &block) | |
| super(name, **options, &block).tap do | |
| if type | |
| # Tries to coerce value to the necessary type |
OlderNewer