sundbp-extlib 0.9.14
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +21 -0
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +47 -0
- data/README.rdoc +17 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/extlib.gemspec +146 -0
- data/lib/extlib.rb +50 -0
- data/lib/extlib/array.rb +36 -0
- data/lib/extlib/assertions.rb +8 -0
- data/lib/extlib/blank.rb +89 -0
- data/lib/extlib/boolean.rb +11 -0
- data/lib/extlib/byte_array.rb +6 -0
- data/lib/extlib/class.rb +177 -0
- data/lib/extlib/datetime.rb +29 -0
- data/lib/extlib/dictionary.rb +433 -0
- data/lib/extlib/hash.rb +442 -0
- data/lib/extlib/hook.rb +403 -0
- data/lib/extlib/inflection.rb +440 -0
- data/lib/extlib/lazy_array.rb +451 -0
- data/lib/extlib/lazy_module.rb +18 -0
- data/lib/extlib/logger.rb +198 -0
- data/lib/extlib/mash.rb +155 -0
- data/lib/extlib/module.rb +47 -0
- data/lib/extlib/nil.rb +5 -0
- data/lib/extlib/numeric.rb +5 -0
- data/lib/extlib/object.rb +175 -0
- data/lib/extlib/object_space.rb +13 -0
- data/lib/extlib/pathname.rb +20 -0
- data/lib/extlib/pooling.rb +235 -0
- data/lib/extlib/rubygems.rb +38 -0
- data/lib/extlib/simple_set.rb +66 -0
- data/lib/extlib/string.rb +176 -0
- data/lib/extlib/struct.rb +17 -0
- data/lib/extlib/symbol.rb +21 -0
- data/lib/extlib/time.rb +43 -0
- data/lib/extlib/virtual_file.rb +10 -0
- data/spec/array_spec.rb +39 -0
- data/spec/blank_spec.rb +85 -0
- data/spec/byte_array_spec.rb +7 -0
- data/spec/class_spec.rb +157 -0
- data/spec/datetime_spec.rb +22 -0
- data/spec/hash_spec.rb +537 -0
- data/spec/hook_spec.rb +1234 -0
- data/spec/inflection/plural_spec.rb +564 -0
- data/spec/inflection/singular_spec.rb +497 -0
- data/spec/inflection_extras_spec.rb +110 -0
- data/spec/lazy_array_spec.rb +1957 -0
- data/spec/lazy_module_spec.rb +38 -0
- data/spec/mash_spec.rb +311 -0
- data/spec/module_spec.rb +70 -0
- data/spec/object_space_spec.rb +9 -0
- data/spec/object_spec.rb +114 -0
- data/spec/pooling_spec.rb +511 -0
- data/spec/rcov.opts +6 -0
- data/spec/simple_set_spec.rb +57 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/string_spec.rb +221 -0
- data/spec/struct_spec.rb +12 -0
- data/spec/symbol_spec.rb +8 -0
- data/spec/time_spec.rb +29 -0
- data/spec/try_call_spec.rb +73 -0
- data/spec/try_dup_spec.rb +45 -0
- data/spec/virtual_file_spec.rb +21 -0
- data/tasks/ci.rake +1 -0
- data/tasks/metrics.rake +36 -0
- data/tasks/spec.rake +25 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +180 -0
data/.autotest
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Autotest.add_hook :initialize do |at|
|
2
|
+
ignore = %w[ .git log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE QUICKLINKS README ]
|
3
|
+
|
4
|
+
ignore.each do |exception|
|
5
|
+
at.add_exception(exception)
|
6
|
+
end
|
7
|
+
|
8
|
+
at.clear_mappings
|
9
|
+
|
10
|
+
at.add_mapping(%r{^spec/.+_spec\.rb$}) do |filename,_|
|
11
|
+
filename
|
12
|
+
end
|
13
|
+
|
14
|
+
at.add_mapping(%r{^lib/extlib/(.+)\.rb$}) do |_,match|
|
15
|
+
[ "spec/#{match[1]}_spec.rb" ]
|
16
|
+
end
|
17
|
+
|
18
|
+
at.add_mapping(%r{^spec/spec_helper\.rb$}) do
|
19
|
+
at.files_matching(%r{^spec/.+_spec\.rb$})
|
20
|
+
end
|
21
|
+
end
|
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
Copyright (c) 2009 Dan Kubb
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
---
|
23
|
+
---
|
24
|
+
|
25
|
+
Some portions of blank.rb and mash.rb are verbatim copies of software
|
26
|
+
licensed under the MIT license. That license is included below:
|
27
|
+
|
28
|
+
Copyright (c) 2005-2008 David Heinemeier Hansson
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
"Software"), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
44
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
45
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
46
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
47
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= extlib
|
2
|
+
|
3
|
+
Support library for DataMapper and Merb.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2009 Dan Kubb. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
gem 'jeweler', '~> 1.4'
|
6
|
+
require 'jeweler'
|
7
|
+
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = 'sundbp-extlib'
|
10
|
+
gem.summary = 'Support library for DataMapper and Merb'
|
11
|
+
gem.description = gem.summary
|
12
|
+
gem.email = 'dan.kubb@gmail.com'
|
13
|
+
gem.homepage = 'http://github.com/datamapper/extlib'
|
14
|
+
gem.authors = [ 'Dan Kubb' ]
|
15
|
+
|
16
|
+
gem.rubyforge_project = 'extlib'
|
17
|
+
|
18
|
+
gem.add_development_dependency 'json_pure', '~> 1.2.0'
|
19
|
+
gem.add_development_dependency 'rspec', '~> 1.2.9'
|
20
|
+
gem.add_development_dependency 'yard', '~> 0.4.0'
|
21
|
+
end
|
22
|
+
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
|
25
|
+
FileList['tasks/**/*.rake'].each { |task| load task }
|
26
|
+
rescue LoadError
|
27
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
28
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.14
|
data/extlib.gemspec
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{extlib}
|
8
|
+
s.version = "0.9.14"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dan Kubb"]
|
12
|
+
s.date = %q{2009-12-11}
|
13
|
+
s.description = %q{Support library for DataMapper and Merb}
|
14
|
+
s.email = %q{dan.kubb@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".autotest",
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"extlib.gemspec",
|
28
|
+
"lib/extlib.rb",
|
29
|
+
"lib/extlib/array.rb",
|
30
|
+
"lib/extlib/assertions.rb",
|
31
|
+
"lib/extlib/blank.rb",
|
32
|
+
"lib/extlib/boolean.rb",
|
33
|
+
"lib/extlib/byte_array.rb",
|
34
|
+
"lib/extlib/class.rb",
|
35
|
+
"lib/extlib/datetime.rb",
|
36
|
+
"lib/extlib/dictionary.rb",
|
37
|
+
"lib/extlib/hash.rb",
|
38
|
+
"lib/extlib/hook.rb",
|
39
|
+
"lib/extlib/inflection.rb",
|
40
|
+
"lib/extlib/lazy_array.rb",
|
41
|
+
"lib/extlib/lazy_module.rb",
|
42
|
+
"lib/extlib/logger.rb",
|
43
|
+
"lib/extlib/mash.rb",
|
44
|
+
"lib/extlib/module.rb",
|
45
|
+
"lib/extlib/nil.rb",
|
46
|
+
"lib/extlib/numeric.rb",
|
47
|
+
"lib/extlib/object.rb",
|
48
|
+
"lib/extlib/object_space.rb",
|
49
|
+
"lib/extlib/pathname.rb",
|
50
|
+
"lib/extlib/pooling.rb",
|
51
|
+
"lib/extlib/rubygems.rb",
|
52
|
+
"lib/extlib/simple_set.rb",
|
53
|
+
"lib/extlib/string.rb",
|
54
|
+
"lib/extlib/struct.rb",
|
55
|
+
"lib/extlib/symbol.rb",
|
56
|
+
"lib/extlib/time.rb",
|
57
|
+
"lib/extlib/virtual_file.rb",
|
58
|
+
"spec/array_spec.rb",
|
59
|
+
"spec/blank_spec.rb",
|
60
|
+
"spec/byte_array_spec.rb",
|
61
|
+
"spec/class_spec.rb",
|
62
|
+
"spec/datetime_spec.rb",
|
63
|
+
"spec/hash_spec.rb",
|
64
|
+
"spec/hook_spec.rb",
|
65
|
+
"spec/inflection/plural_spec.rb",
|
66
|
+
"spec/inflection/singular_spec.rb",
|
67
|
+
"spec/inflection_extras_spec.rb",
|
68
|
+
"spec/lazy_array_spec.rb",
|
69
|
+
"spec/lazy_module_spec.rb",
|
70
|
+
"spec/mash_spec.rb",
|
71
|
+
"spec/module_spec.rb",
|
72
|
+
"spec/object_space_spec.rb",
|
73
|
+
"spec/object_spec.rb",
|
74
|
+
"spec/pooling_spec.rb",
|
75
|
+
"spec/rcov.opts",
|
76
|
+
"spec/simple_set_spec.rb",
|
77
|
+
"spec/spec.opts",
|
78
|
+
"spec/spec_helper.rb",
|
79
|
+
"spec/string_spec.rb",
|
80
|
+
"spec/struct_spec.rb",
|
81
|
+
"spec/symbol_spec.rb",
|
82
|
+
"spec/time_spec.rb",
|
83
|
+
"spec/try_call_spec.rb",
|
84
|
+
"spec/try_dup_spec.rb",
|
85
|
+
"spec/virtual_file_spec.rb",
|
86
|
+
"tasks/ci.rake",
|
87
|
+
"tasks/metrics.rake",
|
88
|
+
"tasks/spec.rake",
|
89
|
+
"tasks/yard.rake",
|
90
|
+
"tasks/yardstick.rake"
|
91
|
+
]
|
92
|
+
s.homepage = %q{http://github.com/datamapper/extlib}
|
93
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
94
|
+
s.require_paths = ["lib"]
|
95
|
+
s.rubyforge_project = %q{extlib}
|
96
|
+
s.rubygems_version = %q{1.3.5}
|
97
|
+
s.summary = %q{Support library for DataMapper and Merb}
|
98
|
+
s.test_files = [
|
99
|
+
"spec/array_spec.rb",
|
100
|
+
"spec/blank_spec.rb",
|
101
|
+
"spec/byte_array_spec.rb",
|
102
|
+
"spec/class_spec.rb",
|
103
|
+
"spec/datetime_spec.rb",
|
104
|
+
"spec/hash_spec.rb",
|
105
|
+
"spec/hook_spec.rb",
|
106
|
+
"spec/inflection/plural_spec.rb",
|
107
|
+
"spec/inflection/singular_spec.rb",
|
108
|
+
"spec/inflection_extras_spec.rb",
|
109
|
+
"spec/lazy_array_spec.rb",
|
110
|
+
"spec/lazy_module_spec.rb",
|
111
|
+
"spec/mash_spec.rb",
|
112
|
+
"spec/module_spec.rb",
|
113
|
+
"spec/object_space_spec.rb",
|
114
|
+
"spec/object_spec.rb",
|
115
|
+
"spec/pooling_spec.rb",
|
116
|
+
"spec/simple_set_spec.rb",
|
117
|
+
"spec/spec_helper.rb",
|
118
|
+
"spec/string_spec.rb",
|
119
|
+
"spec/struct_spec.rb",
|
120
|
+
"spec/symbol_spec.rb",
|
121
|
+
"spec/time_spec.rb",
|
122
|
+
"spec/try_call_spec.rb",
|
123
|
+
"spec/try_dup_spec.rb",
|
124
|
+
"spec/virtual_file_spec.rb"
|
125
|
+
]
|
126
|
+
|
127
|
+
if s.respond_to? :specification_version then
|
128
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
129
|
+
s.specification_version = 3
|
130
|
+
|
131
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
132
|
+
s.add_development_dependency(%q<json_pure>, ["~> 1.2.0"])
|
133
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.2.9"])
|
134
|
+
s.add_development_dependency(%q<yard>, ["~> 0.4.0"])
|
135
|
+
else
|
136
|
+
s.add_dependency(%q<json_pure>, ["~> 1.2.0"])
|
137
|
+
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
|
138
|
+
s.add_dependency(%q<yard>, ["~> 0.4.0"])
|
139
|
+
end
|
140
|
+
else
|
141
|
+
s.add_dependency(%q<json_pure>, ["~> 1.2.0"])
|
142
|
+
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
|
143
|
+
s.add_dependency(%q<yard>, ["~> 0.4.0"])
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
data/lib/extlib.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
# for Pathname /
|
4
|
+
require 'extlib/pathname'
|
5
|
+
require 'extlib/class.rb'
|
6
|
+
require 'extlib/object'
|
7
|
+
require 'extlib/object_space'
|
8
|
+
require 'extlib/array'
|
9
|
+
require 'extlib/string'
|
10
|
+
require 'extlib/symbol'
|
11
|
+
require 'extlib/hash'
|
12
|
+
require 'extlib/mash'
|
13
|
+
require 'extlib/virtual_file'
|
14
|
+
require 'extlib/logger'
|
15
|
+
require 'extlib/time'
|
16
|
+
require 'extlib/datetime'
|
17
|
+
require 'extlib/assertions'
|
18
|
+
require 'extlib/blank'
|
19
|
+
require 'extlib/boolean'
|
20
|
+
require 'extlib/byte_array'
|
21
|
+
require 'extlib/inflection'
|
22
|
+
require 'extlib/lazy_array'
|
23
|
+
require 'extlib/module'
|
24
|
+
require 'extlib/nil'
|
25
|
+
require 'extlib/numeric'
|
26
|
+
require 'extlib/blank'
|
27
|
+
require 'extlib/simple_set'
|
28
|
+
require 'extlib/struct'
|
29
|
+
require 'extlib/symbol'
|
30
|
+
|
31
|
+
Extlib.autoload('Hook', 'extlib/hook')
|
32
|
+
Extlib.autoload('Pooling', 'extlib/pooling')
|
33
|
+
|
34
|
+
module Extlib
|
35
|
+
|
36
|
+
def self.exiting= bool
|
37
|
+
if bool && Extlib.const_defined?('Pooling')
|
38
|
+
if Extlib::Pooling.scavenger?
|
39
|
+
Extlib::Pooling.scavenger.wakeup
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@exiting = true
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.exiting
|
46
|
+
return @exiting if defined?(@exiting)
|
47
|
+
@exiting = false
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/extlib/array.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class Array
|
2
|
+
|
3
|
+
##
|
4
|
+
# Transforms an Array of key/value pairs into a Hash
|
5
|
+
#
|
6
|
+
# This is a better idiom than using Hash[*array.flatten] in Ruby 1.8.6
|
7
|
+
# because it is not possible to limit the flattening to a single
|
8
|
+
# level.
|
9
|
+
#
|
10
|
+
# @return [Hash]
|
11
|
+
# A Hash where each entry in the Array is turned into a key/value
|
12
|
+
#
|
13
|
+
# @api public
|
14
|
+
def to_hash
|
15
|
+
h = {}
|
16
|
+
each { |k,v| h[k] = v }
|
17
|
+
h
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Transforms an Array of key/value pairs into a Mash
|
22
|
+
#
|
23
|
+
# This is a better idiom than using Mash[*array.flatten] in Ruby 1.8.6
|
24
|
+
# because it is not possible to limit the flattening to a single
|
25
|
+
# level.
|
26
|
+
#
|
27
|
+
# @return [Mash]
|
28
|
+
# A Hash where each entry in the Array is turned into a key/value
|
29
|
+
#
|
30
|
+
# @api public
|
31
|
+
def to_mash
|
32
|
+
m = Mash.new
|
33
|
+
each { |k,v| m[k] = v }
|
34
|
+
m
|
35
|
+
end
|
36
|
+
end # class Array
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Extlib
|
2
|
+
module Assertions
|
3
|
+
def assert_kind_of(name, value, *klasses)
|
4
|
+
klasses.each { |k| return if value.kind_of?(k) }
|
5
|
+
raise ArgumentError, "+#{name}+ should be #{klasses.map { |k| k.name } * ' or '}, but was #{value.class.name}", caller(2)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
data/lib/extlib/blank.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
class Object
|
2
|
+
##
|
3
|
+
# Returns true if the object is nil or empty (if applicable)
|
4
|
+
#
|
5
|
+
# [].blank? #=> true
|
6
|
+
# [1].blank? #=> false
|
7
|
+
# [nil].blank? #=> false
|
8
|
+
#
|
9
|
+
# @return [TrueClass, FalseClass]
|
10
|
+
#
|
11
|
+
# @api public
|
12
|
+
def blank?
|
13
|
+
nil? || (respond_to?(:empty?) && empty?)
|
14
|
+
end
|
15
|
+
end # class Object
|
16
|
+
|
17
|
+
class Numeric
|
18
|
+
##
|
19
|
+
# Numerics are never blank
|
20
|
+
#
|
21
|
+
# 0.blank? #=> false
|
22
|
+
# 1.blank? #=> false
|
23
|
+
# 6.54321.blank? #=> false
|
24
|
+
#
|
25
|
+
# @return [FalseClass]
|
26
|
+
#
|
27
|
+
# @api public
|
28
|
+
def blank?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end # class Numeric
|
32
|
+
|
33
|
+
class NilClass
|
34
|
+
##
|
35
|
+
# Nil is always blank
|
36
|
+
#
|
37
|
+
# nil.blank? #=> true
|
38
|
+
#
|
39
|
+
# @return [TrueClass]
|
40
|
+
#
|
41
|
+
# @api public
|
42
|
+
def blank?
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end # class NilClass
|
46
|
+
|
47
|
+
class TrueClass
|
48
|
+
##
|
49
|
+
# True is never blank.
|
50
|
+
#
|
51
|
+
# true.blank? #=> false
|
52
|
+
#
|
53
|
+
# @return [FalseClass]
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def blank?
|
57
|
+
false
|
58
|
+
end
|
59
|
+
end # class TrueClass
|
60
|
+
|
61
|
+
class FalseClass
|
62
|
+
##
|
63
|
+
# False is always blank.
|
64
|
+
#
|
65
|
+
# false.blank? #=> true
|
66
|
+
#
|
67
|
+
# @return [TrueClass]
|
68
|
+
#
|
69
|
+
# @api public
|
70
|
+
def blank?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
end # class FalseClass
|
74
|
+
|
75
|
+
class String
|
76
|
+
##
|
77
|
+
# Strips out whitespace then tests if the string is empty.
|
78
|
+
#
|
79
|
+
# "".blank? #=> true
|
80
|
+
# " ".blank? #=> true
|
81
|
+
# " hey ho ".blank? #=> false
|
82
|
+
#
|
83
|
+
# @return [TrueClass, FalseClass]
|
84
|
+
#
|
85
|
+
# @api public
|
86
|
+
def blank?
|
87
|
+
strip.empty?
|
88
|
+
end
|
89
|
+
end # class String
|