Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'sinatra'
require 'activerecord'
require 'sqlite3'
configure do
ActiveRecord::Base.establish_connection(
:adapter=>'sqlite3', :dbfile=>'delish.db')
@results = ActiveRecord::Base.connection.execute(<<-TABLESQL)
Who: Aaron Blohowiak, copyright 2008 (c) FooMojo, Inc. MIT license.
Why: The Goal of Play It Once, Sam (henceforth: PIOS) is to bring programming
best practices to projects that haven't followed them.
What: In achieving this goal, PIOS is presently a tool that creates Integration
Tests.
# Behavior filter turns method names into select/reject filters
# Example
# class User
# has_manny :comments, :extend => BehaviorFilter
# end
module BehaviorFilter
# creates magic methods like these
# user.comments.from_blocked_commentors
# # => user.comments.select{ |c| user.blocking?(c.commentor) }
def inspect_it(name, thing)
%w{to_s class inspect}.each do |m|
print "#{name}.#{m}: "+ thing.send(m.to_sym)+"\n"
end
end
set_trace_func proc { |event, file, line, id, binding, classname|
%w{event file line id binding classname}.each do |arg|
inspect_it(arg, eval(arg))
end
>> a = Hash.new({})
=> {}
>> a["hi"]["pants"] = "clamdiggers"
=> "clamdiggers"
>> a.inspect
=> "{}"
>> a["hi"]
=> {"pants"=>"clamdiggers"}
>> #hmmmmm...
>>
require 'ostruct'
class Pearl < OpenStruct
alias_method :open_structs_method_missing, :method_missing
def method_missing(meth, *args)
if meth.to_s =~ /=$/
open_structs_method_missing(meth, *args)
else
self.new_ostruct_member(meth)
require 'rubygems'
require 'sinatra'
require 'open-uri'
require 'java'
require File.dirname(__FILE__)+"/jtidy-r938.jar"
Dir.glob(File.dirname(__FILE__)+"/flyingsaucer/*.jar").each do |f|
require f
end
class Face
love = 5
get_love = Proc.new{ love }
puts get_love.call
define_method :get_love, &get_love
def love
:wtf_lol
end
#these are different!!!
(1..10).each do |i|
if i < 5
puts i
else
break
end
end
i=0
10.times{ ++i ; puts i}