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 'strscan' | |
| require 'bigdecimal' | |
| # This is copied and slightly refactored from BareTest::TabularData | |
| # | |
| # Example | |
| # LiteralParser.parse("nil") # => nil | |
| # LiteralParser.parse(":foo") # => :foo |
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' | |
| module ProcToLambda | |
| WORD = Fiddle::SIZEOF_VOIDP | |
| RPROC = 4 * WORD | |
| OFFSET = 32 | |
| VALUE = 2 | |
| refine Proc do | |
| def to_lambda |
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 Papercraft | |
| class Block | |
| def initialize(&) = singleton_class.define_method(:call, &) | |
| def apply(...) = self.class.new { call(...) } | |
| class HTML < Block | |
| def render(...) = call(...) | |
| def to_html = render.to_s | |
| 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
| class Options < Ruby::Box | |
| def [](name) = instance_eval { eval "$#{name.to_s.delete_prefix('$')}" } | |
| end | |
| options = Options.new | |
| options.instance_eval do | |
| require 'optparse' | |
| class Option | |
| def []=(key, value) |
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' | |
| require 'fiddle/import' | |
| module GlobalVariable | |
| extend Fiddle::Importer | |
| dlload Fiddle::Handle::DEFAULT | |
| extern 'void rb_gv_set(const char*, unsigned long)' | |
| extern 'unsigned long rb_gv_get(const char*)' | |
| 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 'io/stream' | |
| require 'open3' | |
| module Command | |
| Result = Data.define(:out, :err, :status) | |
| def self.run(*, **) | |
| Open3.popen3(*, **) do |stdin, stdout, stderr, thread| | |
| stdin.close |
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 Document | |
| def self.included(base) | |
| base.class_eval do | |
| def self.name = "#{super}ument" | |
| end | |
| end | |
| module_function | |
| def print = :printed |
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
| signal = 'ALRM' | |
| status = Signal.list.fetch(signal) + 2**7 | |
| pid = fork do | |
| trap signal do | |
| warn 'Alarm!' | |
| exit status | |
| end | |
| sleep |
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 'stringio' | |
| require 'zlib' | |
| io = StringIO.new('Zip me...') | |
| zipped_io = StringIO.new('', 'a+b') | |
| writer = Zlib::GzipWriter.new(zipped_io) | |
| IO.copy_stream(io, writer) | |
| writer.finish | |
| zipped_io.rewind |
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 IO | |
| module UnbufferedPipe | |
| refine IO.superclass do | |
| def unbuffered_pipe(*, **) | |
| IO.pipe(*, **) do |read_io, write_io| | |
| read_io.sync = true | |
| write_io.sync = true | |
| yield read_io, write_io | |
| end |
NewerOlder