Skip to content

Instantly share code, notes, and snippets.

shalvah /
Last active Nov 5, 2022 — forked from damien-roche/
A Primer on Ruby Method Lookup

A Primer on Ruby Method Lookup

Forked from @damien-roche's gist. Here's my addendum.

Method lookup is a simple affair in most languages without multiple inheritance. You start from the receiver and move up the ancestors chain until you locate the method. Because Ruby allows you to mix in modules and extend singleton classes at runtime, this is an entirely different affair.

I will not build contrived code to exemplify the more complicated aspects of Ruby method lookup, as this will only serve to confuse the matter. If you are having trouble following method lookup in your own programs, it is not because Ruby has strange rules (it does), it is because your code is too tangled.

When you pass a message to an object, here is how Ruby finds what method to call:

shalvah / .yarn-integrity
Created Sep 28, 2022
Package managers interoperability
View .yarn-integrity
"systemParams": "win32-x64-93",
"modulesFolders": [
"flags": [],
"linkedModules": [],
"topLevelPatterns": [
shalvah / sort.php
Created Sep 24, 2022
Mixed multi-level order list sort
View sort.php
$orderList = [
'Scully' => [
'friend' => [
View format.js
// Note: this uses Node.js' `Buffer`, so it might not work in the browser
// You can use a polyfill or write yours.
const RED = [0xFF, 0, 0, 0xFF]; // R, G, B, A
const GREEN = [0, 0xFF, 0, 0xFF];
function serialize(val, outputBytes = []) {
if (typeof val === "string") {
serializeString(val, outputBytes);
} else {
shalvah / event_loop.rb
Last active Apr 29, 2021
Ruby event loop + web server (single thread)
View event_loop.rb
require 'algorithms'
require 'fiber'
class EventLoop
def initialize
@queue =
def run(&entrypoint)
shalvah /
Last active Jan 30, 2021
  1. The page jumps right into the technical innards: "You can embed Flutterwave on your page using our FlutterwaveCheckout() JavaScript function." As a newbie to integrating payments or using Flutterwave, I would have questions. What is Flutterwave Inline? Where dpes the FlutterwaveCheckout function come from? I'd rather start with an explanation of what Flutterwave Inline is about and how to "get it".

  2. This is the home page for Flutterwave Inline, yet installation and setup instructions are not mentioned anywhere, nor is the library linked to. A JavaScript function is mentioned, but where do I find it? I'd start with a brief guide on installing and configuring the JS SDK. If the SDK is hosted on GitHub and has installation and setup instructions there, I'd link to that.

  3. The function responds to your request in accordance with your request configurations.

This statement is a bit complex to grasp at first. For a first draft, Id go with something clearer, like: "After the payment is completed,

shalvah / circular-references-control.js
Last active Sep 25, 2020
Testing garbage collection of circular references in PHP and JS
View circular-references-control.js
// Make sure to run with node --expose-gc
// Control script for the circular references test
// We set circular references, but we remove them explicitly before removing the parent object
// On my machine, memory usage increases by around +1kB at first, then "stabilises" and increases more slowly
(async () => {
while(1) {
let a = {};
let b = {};
a.f = b;
View simple-promise-implementation.js
* Simple promise implementation. Doesn't have all the features of the actual Promise API, + assumes you know what you're doing.
class ToyPromise {
constructor(cb) {
this.state = 'pending';
this._promiseResult = undefined;
this._fulfillmentCallbacks = [];
this._rejectionCallbacks = [];
shalvah / .NET Activity IDs
Created Jul 23, 2020
Examples of System.Diagnostics.Activity structure in .NET
View get-dominant-colour-in-image.js
var Jimp = require('jimp');
const fileName = process.argv[2];
const width = process.argv[3];
const height = process.argv[4];
.then(photo => {
let colours = {};
for (let x = 0; x < width; x++) {