Skip to content

Instantly share code, notes, and snippets.

Stefan Rusterholz apeiros

Block or report user

Report or block apeiros

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
apeiros / binary_tree.rb
Last active Feb 8, 2018 — forked from CodePint/binary_tree.rb
binary tree and nodes
View binary_tree.rb
class Node
attr_accessor :data, :left, :right
def initialize(data)
@left = nil
@right = nil
@data = data
include Comparable
View method_cop.rb
module MethodCop
# guard methods that have side effects with a callback that fires before the method is invoked. If the callback returns a "falsey" value,
# the method is halted and will not be called. The callback will return nil instead.
# if the method does not have side effects or you depend on its return value, you should NOT use this on that method!
def guard_method(guarded_method, guard=nil, &callback)
# normalize guard
guard = method(guard) if guard.is_a?(Symbol)
guard = callback if callback
raise ArgumentError, "You can only supply either a guard argument or a block" if block && guard
View gist:959955
h,m,s = *"23:34:02".match(/\A(\d+):(\d\d):(\d\d)\z/).captures*3600+m.to_i*60+s.to_i
View gist:289074
#!/usr/bin/ruby -w
module Kernel
ValidLocalVariableName = /\A[a-z_]\w*\z/
def empty_binding
proc{ binding }.call
# Dynamically define a bunch of local variables from a hash.
View FIGHT!.txt
$ time ruby1.8 bits.rb 16 > /dev/null
real 0m9.861s
user 0m8.977s
sys 0m0.872s
$ time ruby1.9 bits.rb 16 > /dev/null
real 0m1.742s
user 0m1.740s
View gist:234189
class Object
def chain_method(with_symbol, &new_method)
old_method = method with_symbol
eigenclass = class << self; self; end
eigenclass.class_eval do
define_method with_symbol do |*args| new_method[old_method, *args] end
View car.rb
module Lib
def has_color
define_method(:color) do 'red' end
class Car
extend Lib
You can’t perform that action at this time.