Skip to content

Instantly share code, notes, and snippets.

View benhoskings's full-sized avatar

Ben Hoskings benhoskings

View GitHub Profile
class Object
def new_with &block
self.new.instance_eval {
yield
}
end
end
$logger = Object.new_with {
define_method :foo do
if (results = Parser.new.parse).nil?
# parse failure
else
# displaying help info and exiting is a valid execution method
execute_with_options results
end
def proclol arg
{
'a' => proc { true },
'b' => proc { do_something },
'c' => proc { your_money || your_fase }
}[arg]
end
proclol('b').call
def self.define_the_methods name
(class << self; self; end).instance_eval {
define_method name do |account|
log 'class'
end
}
define_method name do |account|
log 'instance'
end
/* goes in ~/Library/KeyBindings */
{
/* page up/down */
"\UF72C" = "pageUp:";
"\UF72D" = "pageDown:";
/* Modifier keys: start with C-m */
"^m" = {
"^ " = ("insertText:", "\U2423"); /* C-space space */
class Lol
def where_am_i
"within #{self.class.to_s}"
end
def winproc
proc { "lol from #{where_am_i}" }
end
end
def where_am_i
# Where the hell did 'lol' get defined?
method_name = "lol"
ObjectSpace.each_object.each {|o| puts "#{o.is_a?(Class) ? o.name : o.class}: #{o.methods.grep method_name}" unless o.methods.grep(method_name).empty? }
class Object
def metaclass
class << self; self; end
end
end
module CannedScopes
def self.included base
base.send :extend, ClassMethods
end
<VirtualHost *:80>
ServerName mohole.net
ServerAlias www.mohole.net
DocumentRoot /home/mohole/current/public
<Directory "/home/mohole/current/public/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
rightTriangles = [ (a,b,c) | c <- [1..500], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2]
main = print rightTriangles