Skip to content

Instantly share code, notes, and snippets.

class Boggle
@@tree = Marshal.load(File.read('tree.marshal'))
def initialize(grid)
@grid = grid
end
def word_list
list = []
# -*- coding: utf-8 -*-
class Object
def rtry(sym)
self.respond_to?(sym) ? self.send(sym) : nil
end
def barbar(o)
lval = (self.rtry(:blank?) or self.rtry(:empty?)) ? nil : self
rval = (o.rtry(:blank?) or o.rtry(:empty?)) ? nil : o
lval || rval
function project_precmd() {
if [ -z $1 ]; then
export PROJECT_ROOT=$(cd $(project_precmd .); pwd -P)
else
if [[ -d $1/.git || -f $1/Rakefile || -f $1/Makefile ]]; then
echo $1
else
if [[ $(cd $1; pwd -P) == / ]]; then
echo .
else
# Not exactly efficient or legible. Fun though :) -- wtb inject.with_index.
def parentmodules(mod)
mods = mod.split("::")
i=-1
mods.inject([[]]*mods.size) { |a,v|
i += 1
a.zip([mods[i]]*(mods.size-i))
}.map { |e| e.flatten.compact.join("::") }
end
# doesn't really work :(
x = ObjectSpace.each_object.to_a
class Foo
def blah
:asdf
end
end
STATE=:zxcv
blah="asdf"
~/src/ruby-1.8.7-p248 ✖ ❼ ▸ rvm ruby -e 'x=[*(1..10000).map{|e|[1,e]}].sort{|x,y| x[0] <=> y[0]}; y=x.sort; puts y==x'
jruby-1.4.0: jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_15) [x86_64-java]
true
macruby-nightly: MacRuby version 0.6 (ruby 1.9.0) [universal-darwin10.0, x86_64]
false
~/src/ruby-1.8.7-p248 ✖ ❼ ▸ rvm ruby -e 'x=[[1,20],*(1..10000).map{|e|[1,e]}].sort{|x,y| x[0] <=> y[0]}; y=x.sort; puts y==x'
jruby-1.4.0: jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_15) [x86_64-java]
false
macruby-nightly: MacRuby version 0.6 (ruby 1.9.0) [universal-darwin10.0, x86_64]
false
~/src/ruby-1.8.7-p248 ✖ ❼ ▸ rvm ruby -e 'x=[[5,5,5,5],*(1..10000).map{|e|[1,e]}].sort{|x,y| x[0] <=> y[0]}; y=x.sort; puts y==x'
jruby-1.4.0: jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_15) [x86_64-java]
true
macruby-nightly: MacRuby version 0.6 (ruby 1.9.0) [universal-darwin10.0, x86_64]
false
class Person
attr_reader :salutation, :first_name, :last_name
def initialize(s,f,l)
@salutation = s
@first_name = f
@last_name = l
end
require 'active_support/core_ext/proc'
class Migration
def initialize
end
def dsl(&block)
block.bind(self).call