public
Description: My assistance repo w/ minor tweaks (original @ http://assistance.rubyforge.org/svn/trunk)
Homepage: http://assistance.rubyforge.org
Clone URL: git://github.com/bricooke/assistance.git
Search Repo:
Imported #blank? from DataMapper.

git-svn-id: http://assistance.rubyforge.org/svn/trunk@11 
76a3b97d-4fa4-4887-8470-eb0d8fc1b0f2
ciconia (author)
Thu Jan 10 09:39:07 -0800 2008
commit  dd5601ff66a387ce392775c0d1824ea1163f29f3
tree    0e98c6d8a9b1e7873d827446daa9d5bdac87ca08
parent  e260f90c5916adfdf2ad1f257767493d4af4e38e
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 === SVN
0
 
0
+* Imported #blank? from DataMapper.
0
+
0
 * Imported inflector from Merb.
0
 
0
 * Imported ConnectionPool from Sequel.
0
...
1
2
3
...
 
 
1
0
@@ -1,4 +1,2 @@
0
-* Object#blank?.
0
-
0
 * code statistics? (from sequel).
...
4
5
6
 
7
...
4
5
6
7
8
0
@@ -4,5 +4,6 @@
0
   time_calculations
0
   connection_pool
0
   inflector
0
+ blank
0
 ].each {|f| require(File.join(dir, f))}
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
0
@@ -1 +1,36 @@
0
+class Object
0
+ def blank?
0
+ nil? || (respond_to?(:empty?) && empty?)
0
+ end
0
+end
0
+
0
+class Numeric
0
+ def blank?
0
+ false
0
+ end
0
+end
0
+
0
+class NilClass
0
+ def blank?
0
+ true
0
+ end
0
+end
0
+
0
+class TrueClass
0
+ def blank?
0
+ false
0
+ end
0
+end
0
+
0
+class FalseClass
0
+ def blank?
0
+ true
0
+ end
0
+end
0
+
0
+class String
0
+ def blank?
0
+ empty? || self =~ /\A\s*\Z/
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
0
@@ -1 +1,9 @@
0
+require File.join(File.dirname(__FILE__), 'spec_helper')
0
+
0
+describe "blank?" do
0
+ it "should mark empty objects as blank" do
0
+ [ nil, false, '', ' ', " \n\t \r ", [], {} ].each { |f| f.should be_blank }
0
+ [ Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ].each { |t| t.should_not be_blank }
0
+ end
0
+end

Comments

    No one has commented yet.