Browse files

Moving plugins into a central repo instead of having them scattered a…

…ll over
  • Loading branch information...
0 parents commit dccb437a91dd90d128e798c338363321b9f889be @UnderpantsGnome committed Mar 4, 2007
Showing with 60 additions and 0 deletions.
  1. +1 −0 init.rb
  2. +59 −0 lib/core_extensions.rb
1 init.rb
@@ -0,0 +1 @@
+require 'core_extensions'
59 lib/core_extensions.rb
@@ -0,0 +1,59 @@
+# http://pastie.caboo.se/10707
+class Hash
+ # Usage { :a => 1, :b => 2, :c => 3}.except(:a) -> { :b => 2, :c => 3}
+ def except(*keys)
+ self.reject { |k,v|
+ keys.include? k.to_sym
+ }
+ end
+
+ # Usage { :a => 1, :b => 2, :c => 3}.only(:a) -> {:a => 1}
+ def only(*keys)
+ self.dup.reject { |k,v|
+ !keys.include? k.to_sym
+ }
+ end
+end
+
+class Array
+ def shuffle
+ dup.shuffle!
+ end
+
+ def shuffle!
+ each_index do |i|
+ j = rand(length-i) + i
+ self[j], self[i] = self[i], self[j]
+ end
+ end
+end
+
+# fix the partials in action mailer tempates that still haven't been fixed
+# http://dev.rubyonrails.org/ticket/2926
+module ActionMailer
+ class Base
+ def self.controller_path
+ ''
+ end
+ end
+end
+
+# http://www.ruby-forum.com/topic/75258
+module Kernel
+private
+ def this_method
+ caller[0] =~ /`([^']*)'/ and $1
+ end
+end
+
+class NilClass
+ def useful?
+ false
+ end
+end
+
+class String
+ def useful?
+ ((self.length == 0) || self !~ /\S/) ? false : true
+ end
+end

0 comments on commit dccb437

Please sign in to comment.