🏳️⚧️
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" | |
| require "net/http" | |
| require "uri" | |
| # The standard library Net::HTTP module is a bit convoluted, but here is an example of a flexible | |
| # system for making different kinds of HTTP requests. To see some convenience methods you can | |
| # consult the docs: https://ruby-doc.org/stdlib-2.5.5/libdoc/net/http/rdoc/Net/HTTP.html | |
| class HttpConnection | |
| def get(url, params = nil) |
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 Expectation | |
| def to(matcher = nil, &block) | |
| if block_given? | |
| puts "block passed to `to` method" | |
| yield | |
| end | |
| end | |
| end | |
| def expect |
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
| --skip-action-mailer | |
| --skip-action-mailbox | |
| --skip-action-text | |
| --skip-active-job | |
| --skip-active-storage | |
| --skip-action-cable | |
| --skip-jbuilder | |
| --skip-bootsnap |
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
| # If you want to check whether a string matches a regular expression, | |
| # but not return the match data, you can just use === the case equality operator. | |
| # Bad | |
| !! ('foobar' =~ /bar/) #=> true | |
| !! ('foo' =~ /bar/) #=> false | |
| # Good | |
| /bar/ === 'foobar' #=> true | |
| /bar/ === 'foo' #=> false |
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
| RSpec::Matchers.define :notify_bugsnag do |error = nil, message = nil| | |
| supports_block_expectations | |
| match do |block| | |
| if error | |
| expect(Bugsnag).to receive(:notify).with(instance_of(error)) | |
| else | |
| expect(Bugsnag).to receive(:notify) | |
| 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
| module Foo | |
| def foo | |
| blah | |
| end | |
| private def blah | |
| "foo" | |
| end | |
| 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
| def beep(a, b) | |
| result = "" | |
| result += a.to_s | |
| if a && b | |
| result += " and " | |
| end | |
| result += b.to_s | |
| end | |
| puts beep("foo", "bar") |
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 "time" | |
| p now = Time.parse("2020-08-07") | |
| p date = Time.parse("2013-08-07") | |
| delta, _ = (now.to_i - date.to_i).divmod(24 * 60 * 60) | |
| years, rest = delta.divmod(365) | |
| months, days = rest.divmod(30) | |
| puts "years: #{years}" | |
| puts "months: #{months}" |
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
| #!/usr/bin/env ruby | |
| require "psych" | |
| require "pry" | |
| # Handler for detecting scalar values | |
| class YayHandler < Psych::Handler | |
| # States: | |
| # a -> start_map -> b | |
| # b -> scalar -> c (push key) |
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
| #!/bin/sh | |
| # Simplified from this script, (less robust and more to the point): | |
| # http://gmodarelli.com/2015/02/code-reviews-rubocop-git-pre-commit/ | |
| # Installation: copy this code into <REPO>.git/hooks/pre-commit.sh | |
| # Select only staged Ruby files | |
| FILES="$(git diff --cached --name-only --diff-filter=AMC | grep "\.rb$" | tr '\n' ' ')" |
NewerOlder