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' | |
| condition = Async::Condition.new | |
| Async do | |
| task_one = Async do | |
| loop do | |
| puts 'task one before waiting' | |
| condition.wait | |
| 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 | |
| class Node | |
| attr_reader :value | |
| attr_reader :parent | |
| def initialize(value:, parent: nil) | |
| @value = value | |
| @parent = parent | |
| 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
| require 'erb' | |
| require 'psych' | |
| topic = :users | |
| users = %w[wombat fox poodle] | |
| template = ERB.new <<~END, trim_mode: '-' | |
| --- | |
| :<%= topic %>: | |
| <%- users.each do |user| %> |
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 initialize(a, b, c:) | |
| puts 'Foo!' | |
| end | |
| end | |
| class MakeItWork < Foo | |
| def initialize(*args, **kwargs, &block) | |
| parameters = method(__method__).super_method.parameters |
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 ResponseEnumerator < Enumerator | |
| DEFAULT_PER_PAGE = 25 | |
| attr_accessor :per_page | |
| def initialize(square, http_verb:, path:, data:, | |
| fields:, parameters: {}, memoize: true, per_page: nil) | |
| @per_page = per_page || DEFAULT_PER_PAGE | |
| @memoized_responses = [] | |
| @params = parameters.fetch :params |
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
| secret = 'cicada' | |
| key = 'wombat' | |
| cipher = OpenSSL::Cipher::AES256.new :CBC | |
| cipher.encrypt | |
| salt = OpenSSL::Random.random_bytes 16 | |
| cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1 key, salt, 20000, 32 | |
| iv = cipher.random_iv |
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 FerretString < String | |
| def to_s | |
| 'Successfully overrode ...' | |
| end | |
| end | |
| class WombatString < DelegateClass(String) | |
| def initialize | |
| super('') | |
| 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 sig(method_name) | |
| meth = method(method_name) | |
| parameters = meth.parameters.map do |type, name| | |
| case type | |
| when :req | |
| name | |
| when :rest | |
| "*#{name}" | |
| when :opt | |
| # Unknown default argument. |
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 'fileutils' | |
| require 'find' | |
| require 'zlib' | |
| binaries_dir = File.join Gem.dir, 'binaries' | |
| gems_dir = File.join Gem.dir, 'gems' | |
| Dir['*/', base: gems_dir].each do |gem| |
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 Heater | |
| STATE = { | |
| s1: {heater: false, cooler: false}, | |
| s2: {heater: false, cooler: true}, | |
| s3: {heater: true, cooler: false} | |
| }.freeze | |
| attr_reader :state |