├── README ├── init.rb └── lib ├── active_record.rb ├── enumerable.rb ├── object.rb ├── rails.rb └── string.rb /README: -------------------------------------------------------------------------------- 1 | THIS PROJECT IS UNMAINTAINED - it is here for novel historic value. 2 | 3 | This project is an extraction from GitHub. 4 | 5 | For this and other extractions, see http://github.com/github 6 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | Dir[File.dirname(__FILE__) + "/lib/**/*.rb"].each do |file| 2 | require file 3 | end 4 | -------------------------------------------------------------------------------- /lib/active_record.rb: -------------------------------------------------------------------------------- 1 | class << ActiveRecord::Base 2 | def each(limit = 1000) 3 | rows = find(:all, :conditions => ["id > ?", 0], :limit => limit) 4 | until rows.blank? 5 | rows.each { |record| yield record } 6 | rows = find(:all, :conditions => ["id > ?", rows.last.id], :limit => limit) 7 | end 8 | self 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/enumerable.rb: -------------------------------------------------------------------------------- 1 | module Enumerable 2 | def map_with_index 3 | result = [] 4 | self.each_with_index do |elt, idx| 5 | result << yield(elt, idx) 6 | end 7 | result 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/object.rb: -------------------------------------------------------------------------------- 1 | class Object 2 | # Metaid == a few simple metaclass helper 3 | # (See http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html.) 4 | # The hidden singleton lurks behind everyone 5 | def metaclass() class << self; self end end 6 | def meta_eval(&blk) metaclass.instance_eval(&blk) end 7 | 8 | # Adds methods to a metaclass 9 | def meta_def(name, &blk) 10 | meta_eval { define_method(name, &blk) } 11 | end 12 | 13 | # Defines an instance method within a class 14 | def class_def(name, &blk) 15 | class_eval { define_method(name, &blk) } 16 | end 17 | 18 | ## 19 | # if ''.not.blank? 20 | # http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html 21 | define_method :not do 22 | Not.new(self) 23 | end 24 | 25 | class Not 26 | private *instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ } 27 | 28 | def initialize(subject) 29 | @subject = subject 30 | end 31 | 32 | def method_missing(sym, *args, &blk) 33 | !@subject.send(sym,*args,&blk) 34 | end 35 | end 36 | 37 | ## 38 | # @person ? @person.name : nil 39 | # vs 40 | # @person.try(:name) 41 | def try(method) 42 | send method if respond_to? method 43 | end 44 | 45 | def class_attr_accessor(*attrs) 46 | metaclass.send(:attr_accessor, *attrs) 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/rails.rb: -------------------------------------------------------------------------------- 1 | module Rails 2 | def self.environment 3 | ENV['RAILS_ENV'].to_s.downcase 4 | end 5 | 6 | def self.development? 7 | environment == 'development' 8 | end 9 | 10 | def self.production? 11 | environment == 'production' 12 | end 13 | 14 | def self.test? 15 | environment == 'test' 16 | end 17 | 18 | def self.none? 19 | environment.empty? 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/string.rb: -------------------------------------------------------------------------------- 1 | class String 2 | def to_md5 3 | Digest::MD5.hexdigest(self) 4 | end 5 | end 6 | --------------------------------------------------------------------------------