Skip to content

Instantly share code, notes, and snippets.

module Foo
def self.included(klass)
klass.extend ClassMethods
end
module ClassMethods
def foo(name)
(class << self; self; end).send :attr_accessor, name
end
end
end
@chad
chad / exporter.rb
Created February 26, 2012 18:57 — forked from jcasimir/exporter.rb
Export ActiveRecord Tables to CSV
require 'csv'
module Exporter
DEFAULT_EXPORT_TABLES = [ Invoice, InvoiceItem, Item, Merchant, Transaction, User ]
DESTINATION_FOLDER = "tmp/"
def self.included(klass)
klass.extend ClassLevelMethods
end
@chad
chad / dict.rb
Created December 17, 2011 14:42 — forked from latompa/dict.rb
simple dictionary without using arrays or hashes
def add(key, value, dictionary = Proc.new{})
lambda do |x|
key == x ? value : dictionary.call(x)
end
end
d = add("a",5)
d = add("b",6, d)
p d.call("b")
# *&^)^(&(&&*^)^(* encoding: utf-8 *)*)&)^)^%*%&*%**
ÜglÈÊCÕnsªnt = "HAIUGLYCODEZ"
alias :send ∴; alias :get ∵
%w|rubygems sinatra|.each{|_|require _}
%w|gem load|.each{|_| ∴ _, 'kitty'}
(℧=Kitty).∴ *%w(define_method print) do |*⇧| ⇧.∴:join end
∵ %r{\/} do content_type "nialp/txet".reverse and ℧.new.random_kitty end
# gem install kitty
# ruby kitty_server.rb &
# curl http://localhost:4567
def create
@user = User.new(params[:user])
pw_match!
if @user.save
flash[:notice] = "User created"
redirect_to admin_url
else
render :action => "new"
end
end