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
| # frozen_string_literal: true | |
| require 'delegate' | |
| class Fiberator < DelegateClass Fiber | |
| class Rewind < StandardError | |
| end | |
| NOTHING = Object.new | |
| private_constant :NOTHING |
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
| # Ruby 1.9 | |
| Hash[collection.group_by { |n| n }.map { |k, v| [k, v.size] }] | |
| # Ruby 2.0 Array#to_h | |
| collection.group_by { |n| n }.map { |k, v| [k, v.size] }.to_h | |
| # Ruby 2.2 Object#itself | |
| collection.group_by(&:itself).map { |k, v| [k, v.size] }.to_h | |
| # Ruby 2.4 Hash#transform_values |
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 RedInspect | |
| REFINED = [NilClass, Array, Array.singleton_class].freeze | |
| def inspect | |
| "\e[91m#{super}\e[0m" | |
| end | |
| self.then do |oneself| | |
| REFINED.each { refine(_1) { include oneself } } | |
| 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 SizeSquared | |
| [String, Enumerable].each do |this_class| | |
| refine this_class do | |
| def size_squared | |
| size.abs2 | |
| end | |
| alias length_squared size_squared | |
| end | |
| 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
| # frozen_string_literal: true | |
| fetcher = Gem::SpecFetcher.fetcher | |
| matches = fetcher.detect do |spec| | |
| spec.name.start_with? 'jekyll-' | |
| end | |
| plugins = matches.map(&:first).map(&:name).uniq |
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 'async' | |
| require 'async/notification' | |
| def do_a_thing_lasting(duration) | |
| puts 'hi' | |
| sleep duration | |
| puts 'bye' | |
| end | |
| def now_and_every(interval) |
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 | |
| # frozen_string_literal: true | |
| require 'async' | |
| require 'async/barrier' | |
| require 'async/http/client' | |
| require 'async/http/endpoint' | |
| require 'async/logger' | |
| require 'optionparser' |
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
| chars = str | |
| .split | |
| .map(&:chars) | |
| .reduce(&:zip) | |
| .each_slice(2) | |
| .map(&:join) | |
| .map(&:chars) | |
| chars.map { |char| char.map(&HASH) } |
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
| foo = Object.new | |
| def foo.value | |
| 42 | |
| end | |
| foo.value | |
| #=> 42 | |
| bar = Object.new |
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
| # frozen_string_literal: true | |
| class Optional | |
| attr_reader :value | |
| def initialize(value) | |
| @value = value | |
| end | |
| def then(&block) |