This file contains 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
"Michael Abrash", | |
"Scott Adams (game designer)", | |
"Tarn Adams", | |
"Leonard Adleman", | |
"Alfred Aho", | |
"Andrei Alexandrescu", | |
"Paul Allen", | |
"Eric Allman", | |
"Marc Andreessen", | |
"Jeremy Ashkenas", |
This file contains 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 'syntax_tree' | |
class RSpecEnvironment | |
def initialize | |
@contexts = [] | |
@results = [] | |
end | |
def klass(k) | |
@contexts << k |
This file contains 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 MyStringScanner | |
class ScanError < StandardError; end | |
attr_reader :string, :captures | |
attr_accessor :pos | |
def initialize(string, _obsolete = false, fixed_anchor: false) | |
@string = string | |
@fixed_anchor = fixed_anchor | |
@pos = 0 | |
@previous_pos = 0 |
This file contains 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 self.included(base) | |
base.instance_variable_set(:@count, 0) unless base.instance_variable_defined?(:@count) | |
base.instance_variable_set(:@count, base.instance_variable_get(:@count) + 1) | |
puts base.name if base.instance_variable_get(:@count) > 1 | |
end |
This file contains 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 Hash | |
def transform(&block) | |
new_hash = {} | |
each_pair do |key, value| | |
rtn = block.call(key, value) | |
case rtn | |
in nil | true then new_hash[key] = value | |
in false then next | |
in Array[[_, _], *] | |
rtn.each do |k, v| |
This file contains 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
MAPPING = { | |
a: 1, | |
b: 2, | |
c: 3, | |
d: 4, | |
e: 5, | |
f: 6, | |
}.freeze | |
def method1(key) |
This file contains 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 Kernel | |
def ice(key, value, on: Object) | |
if on.instance_methods.include?(key.to_sym) | |
prev = on.instance_method(key) | |
on.define_method key do | |
on.remove_method key | |
on.define_method(key, prev) | |
return value | |
end | |
else |
This file contains 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 Module | |
def define_mixable_method(name:, calls:, main:) | |
define_method(name) do |&block| | |
method_candidates = calls.map {|name| method(name) } | |
block.call(main, method_candidates).each do |m| | |
m.call | |
end | |
end | |
end | |
end |
This file contains 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 EachWithEffect | |
DEFAULT = Object.new.freeze | |
def each_with_effect(effect_handlers = {}, &block) | |
effect = catch(:effect) do | |
block.call(self.peek) | |
end | |
if effect | |
handler = effect_handlers.find{ |k, v| k === effect }&.last || effect_handlers.fetch(DEFAULT) | |
alternative = handler.call(effect) if handler |
This file contains 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 WithEffect | |
def initialize | |
@list = ["Foo", "Bar", 42, "Baz"] | |
end | |
def process_item(item) | |
throw(:item_not_string, 42) unless item.is_a?(String) | |
puts item | |
end |
NewerOlder