Skip to content

Instantly share code, notes, and snippets.

View kbaird's full-sized avatar
💭
Homo sapiens... for now.

Kevin C. Baird kbaird

💭
Homo sapiens... for now.
View GitHub Profile
@peterc
peterc / methods_returning.rb
Last active October 29, 2023 03:10
Object#methods_returning - to work out which method on an object returns what we want
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
@postmodern
postmodern / array_comprehension.rb
Created October 1, 2010 07:50
Adds Haskell style list comprehensions to the Ruby Array
class Array
#
# Iterates over each permutation of the enumerable values within the
# {Array}.
#
# @yield [list]
# The given block will be passed each permutation of the enumerable
# values in the {Array}.
#