quality_extensions 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme +54 -0
- data/lib/qualitysmith_extensions/all.rb +4 -0
- data/lib/qualitysmith_extensions/array/all.rb +2 -0
- data/lib/qualitysmith_extensions/array/average.rb +44 -0
- data/lib/qualitysmith_extensions/array/classify.rb +97 -0
- data/lib/qualitysmith_extensions/array/expand_ranges.rb +52 -0
- data/lib/qualitysmith_extensions/array/group_by.rb +134 -0
- data/lib/qualitysmith_extensions/array/sequence.rb +66 -0
- data/lib/qualitysmith_extensions/array/shell_escape.rb +36 -0
- data/lib/qualitysmith_extensions/array/to_a_recursive.rb +41 -0
- data/lib/qualitysmith_extensions/array/to_query_string.rb +96 -0
- data/lib/qualitysmith_extensions/collection_extensions_for_cgi.rb +2 -0
- data/lib/qualitysmith_extensions/colored/toggleability.rb +62 -0
- data/lib/qualitysmith_extensions/console/command.facets.1.8.51.rb +749 -0
- data/lib/qualitysmith_extensions/console/command.facets.1.8.54.rb +748 -0
- data/lib/qualitysmith_extensions/console/command.rb +944 -0
- data/lib/qualitysmith_extensions/date/all.rb +2 -0
- data/lib/qualitysmith_extensions/date/deprecated.rb +40 -0
- data/lib/qualitysmith_extensions/date/iso8601.rb +31 -0
- data/lib/qualitysmith_extensions/date/month_ranges.rb +122 -0
- data/lib/qualitysmith_extensions/dir/each_child.rb +58 -0
- data/lib/qualitysmith_extensions/enumerable/enum.rb +69 -0
- data/lib/qualitysmith_extensions/enumerable/select_until.rb +4 -0
- data/lib/qualitysmith_extensions/enumerable/select_while.rb +109 -0
- data/lib/qualitysmith_extensions/exception/inspect_with_backtrace.rb +65 -0
- data/lib/qualitysmith_extensions/file/exact_match_regexp.rb +34 -0
- data/lib/qualitysmith_extensions/file_test/binary_file.rb +110 -0
- data/lib/qualitysmith_extensions/find/select.rb +68 -0
- data/lib/qualitysmith_extensions/global_variable_set.rb +153 -0
- data/lib/qualitysmith_extensions/hash/all.rb +2 -0
- data/lib/qualitysmith_extensions/hash/to_date.rb +34 -0
- data/lib/qualitysmith_extensions/hash/to_query_string.rb +121 -0
- data/lib/qualitysmith_extensions/kernel/all.rb +2 -0
- data/lib/qualitysmith_extensions/kernel/autoreload.rb +128 -0
- data/lib/qualitysmith_extensions/kernel/backtrace.rb +71 -0
- data/lib/qualitysmith_extensions/kernel/capture_output.rb +115 -0
- data/lib/qualitysmith_extensions/kernel/die.rb +49 -0
- data/lib/qualitysmith_extensions/kernel/example_printer.rb +81 -0
- data/lib/qualitysmith_extensions/kernel/filter_output.rb +108 -0
- data/lib/qualitysmith_extensions/kernel/remove_const.rb +178 -0
- data/lib/qualitysmith_extensions/kernel/remove_module.rb +127 -0
- data/lib/qualitysmith_extensions/kernel/require_all.rb +186 -0
- data/lib/qualitysmith_extensions/kernel/require_local_all.rb +4 -0
- data/lib/qualitysmith_extensions/kernel/require_once.rb +18 -0
- data/lib/qualitysmith_extensions/kernel/simulate_input.rb +52 -0
- data/lib/qualitysmith_extensions/kernel/trap_chain.rb +61 -0
- data/lib/qualitysmith_extensions/kernel/windows_platform.rb +46 -0
- data/lib/qualitysmith_extensions/module/alias_method.rb +6 -0
- data/lib/qualitysmith_extensions/module/alias_method_chain.rb +165 -0
- data/lib/qualitysmith_extensions/module/ancestry_of_instance_method.rb +43 -0
- data/lib/qualitysmith_extensions/module/attribute_accessors.rb +49 -0
- data/lib/qualitysmith_extensions/module/basename.rb +76 -0
- data/lib/qualitysmith_extensions/module/bool_attr_accessor.rb +497 -0
- data/lib/qualitysmith_extensions/module/class_methods.rb +87 -0
- data/lib/qualitysmith_extensions/module/create.rb +315 -0
- data/lib/qualitysmith_extensions/module/create_setter.rb +9 -0
- data/lib/qualitysmith_extensions/module/dirname.rb +4 -0
- data/lib/qualitysmith_extensions/module/guard_method.rb +312 -0
- data/lib/qualitysmith_extensions/module/includable_once.rb +10 -0
- data/lib/qualitysmith_extensions/module/join.rb +66 -0
- data/lib/qualitysmith_extensions/module/malias_method_chain.rb +92 -0
- data/lib/qualitysmith_extensions/module/module_methods.rb +4 -0
- data/lib/qualitysmith_extensions/module/namespace.rb +112 -0
- data/lib/qualitysmith_extensions/module/parents.rb +61 -0
- data/lib/qualitysmith_extensions/module/remove_const.rb +117 -0
- data/lib/qualitysmith_extensions/module/split.rb +55 -0
- data/lib/qualitysmith_extensions/month.rb +66 -0
- data/lib/qualitysmith_extensions/mutex/if_available.rb +75 -0
- data/lib/qualitysmith_extensions/object/ancestry_of_method.rb +257 -0
- data/lib/qualitysmith_extensions/object/default.rb +69 -0
- data/lib/qualitysmith_extensions/object/if_else.rb +157 -0
- data/lib/qualitysmith_extensions/object/ignore_access.rb +84 -0
- data/lib/qualitysmith_extensions/object/mcall.rb +92 -0
- data/lib/qualitysmith_extensions/object/methods.rb +63 -0
- data/lib/qualitysmith_extensions/object/send_if.rb +151 -0
- data/lib/qualitysmith_extensions/object/send_if_not_nil.rb +35 -0
- data/lib/qualitysmith_extensions/object/singleton_send.rb +129 -0
- data/lib/qualitysmith_extensions/regexp/join.rb +111 -0
- data/lib/qualitysmith_extensions/string/all.rb +2 -0
- data/lib/qualitysmith_extensions/string/constantize.rb +4 -0
- data/lib/qualitysmith_extensions/string/digits_only.rb +27 -0
- data/lib/qualitysmith_extensions/string/each_char_with_index.rb +41 -0
- data/lib/qualitysmith_extensions/string/md5.rb +29 -0
- data/lib/qualitysmith_extensions/string/shell_escape.rb +43 -0
- data/lib/qualitysmith_extensions/string/to_underscored_label.rb +37 -0
- data/lib/qualitysmith_extensions/string/with_knowledge_of_color.rb +64 -0
- data/lib/qualitysmith_extensions/symbol/constantize.rb +69 -0
- data/lib/qualitysmith_extensions/symbol/match.rb +157 -0
- data/lib/qualitysmith_extensions/template.rb +33 -0
- data/lib/qualitysmith_extensions/test/all.rb +2 -0
- data/lib/qualitysmith_extensions/test/assert_anything.rb +93 -0
- data/lib/qualitysmith_extensions/test/assert_changed.rb +66 -0
- data/lib/qualitysmith_extensions/test/assert_exception.rb +66 -0
- data/lib/qualitysmith_extensions/test/assert_includes.rb +36 -0
- data/lib/qualitysmith_extensions/test/assert_user_error.rb +37 -0
- data/lib/qualitysmith_extensions/test/difference_highlighting.rb +323 -0
- data/lib/qualitysmith_extensions/time/all.rb +2 -0
- data/lib/qualitysmith_extensions/time/deprecated.rb +31 -0
- data/test/all.rb +16 -0
- metadata +148 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
# Developer notes::
|
7
|
+
# Changes::
|
8
|
+
#++
|
9
|
+
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
require 'facets/core/symbol/to_proc'
|
13
|
+
require 'qualitysmith_extensions/symbol/constantize'
|
14
|
+
require 'qualitysmith_extensions/module/namespace' # dirname
|
15
|
+
require 'qualitysmith_extensions/module/basename'
|
16
|
+
|
17
|
+
class Module
|
18
|
+
# Joins pieces of a "module path" together in the same sense that <tt>File.join</tt> joins pieces of a _filesystem_ path.
|
19
|
+
#
|
20
|
+
# See also <tt>Module.dirname</tt>/<tt>Module.namespace_name_of</tt> and <tt>Module.basename</tt>.
|
21
|
+
#
|
22
|
+
# These can be used together, such that the following is always true:
|
23
|
+
# OuterModule::MiddleModule::InnerModule == Module.join(Module.dirname(some_module), Module.basename(some_module)).constantize
|
24
|
+
#
|
25
|
+
def self.join(*path_parts)
|
26
|
+
path_parts.map(&:to_s).join('::')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
# _____ _
|
34
|
+
# |_ _|__ ___| |_
|
35
|
+
# | |/ _ \/ __| __|
|
36
|
+
# | | __/\__ \ |_
|
37
|
+
# |_|\___||___/\__|
|
38
|
+
#
|
39
|
+
=begin test
|
40
|
+
require 'test/unit'
|
41
|
+
|
42
|
+
module OuterModule; end
|
43
|
+
module OuterModule::MiddleModule; end
|
44
|
+
module OuterModule::MiddleModule::InnerModule; end
|
45
|
+
|
46
|
+
class JoinTest < Test::Unit::TestCase
|
47
|
+
def test_join
|
48
|
+
assert_equal 'OuterModule::MiddleModule::InnerModule',
|
49
|
+
Module.join('OuterModule', 'MiddleModule', 'InnerModule')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class TeamworkTest < Test::Unit::TestCase
|
54
|
+
def test_join
|
55
|
+
assert_equal ['OuterModule::MiddleModule', 'InnerModule'],
|
56
|
+
[Module.dirname(OuterModule::MiddleModule::InnerModule), Module.basename(OuterModule::MiddleModule::InnerModule)]
|
57
|
+
assert_equal 'OuterModule::MiddleModule::InnerModule',
|
58
|
+
Module.join(Module.dirname(OuterModule::MiddleModule::InnerModule), Module.basename(OuterModule::MiddleModule::InnerModule))
|
59
|
+
assert_equal OuterModule::MiddleModule::InnerModule,
|
60
|
+
Module.join(Module.dirname(OuterModule::MiddleModule::InnerModule), Module.basename(OuterModule::MiddleModule::InnerModule)).constantize
|
61
|
+
end
|
62
|
+
end
|
63
|
+
=end
|
64
|
+
|
65
|
+
|
66
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
# Developer notes::
|
7
|
+
# Changes::
|
8
|
+
#++
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
gem 'facets'
|
12
|
+
require 'facets/core/kernel/singleton_class'
|
13
|
+
require 'qualitysmith_extensions/module/alias_method_chain'
|
14
|
+
|
15
|
+
class Module
|
16
|
+
|
17
|
+
# Same as <tt>Module#alias_method_chain</tt>, only it works for modules/classes
|
18
|
+
#
|
19
|
+
# class X
|
20
|
+
# def self.foo
|
21
|
+
# 'foo'
|
22
|
+
# end
|
23
|
+
# malias_method_chain :foo, :feature
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Note: You could always do the same thing with <tt>Module#alias_method_chain</tt> by simply doing this:
|
27
|
+
#
|
28
|
+
# class << self
|
29
|
+
# alias_method_chain :foo, :feature
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
def malias_method_chain(target, feature, *args)
|
33
|
+
# Strip out punctuation on predicates or bang methods since
|
34
|
+
# e.g. target?_without_feature is not a valid method name.
|
35
|
+
|
36
|
+
singleton_class.instance_eval do
|
37
|
+
alias_method_chain target, feature, *args
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# _____ _
|
45
|
+
# |_ _|__ ___| |_
|
46
|
+
# | |/ _ \/ __| __|
|
47
|
+
# | | __/\__ \ |_
|
48
|
+
# |_|\___||___/\__|
|
49
|
+
#
|
50
|
+
=begin test
|
51
|
+
require 'test/unit'
|
52
|
+
|
53
|
+
class TestHowYouWouldDoItWithPlain_alias_method_chain < Test::Unit::TestCase
|
54
|
+
|
55
|
+
class X
|
56
|
+
def self.foo
|
57
|
+
'foo'
|
58
|
+
end
|
59
|
+
def self.foo_with_feature
|
60
|
+
foo_without_feature + '_with_feature'
|
61
|
+
end
|
62
|
+
class << self
|
63
|
+
alias_method_chain :foo, :feature
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_001
|
68
|
+
assert_equal 'foo_with_feature', X.foo
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class Test_malias_method_chain < Test::Unit::TestCase
|
74
|
+
|
75
|
+
class Y
|
76
|
+
def self.foo
|
77
|
+
'foo'
|
78
|
+
end
|
79
|
+
def self.foo_with_feature
|
80
|
+
foo_without_feature + '_with_feature'
|
81
|
+
end
|
82
|
+
malias_method_chain :foo, :feature
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_001
|
86
|
+
assert_equal 'foo_with_feature', Y.foo
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
=end
|
92
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
# Developer notes::
|
7
|
+
# Changes::
|
8
|
+
# * 0.0.52: Renamed namespace to namespace_module to avoid conflicting with Facets' Module#namespace and Rake's namespace
|
9
|
+
#++
|
10
|
+
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'qualitysmith_extensions/symbol/constantize'
|
14
|
+
require 'qualitysmith_extensions/module/split'
|
15
|
+
|
16
|
+
|
17
|
+
class Module
|
18
|
+
# Return the module which contains this one; if this is a root module, such as
|
19
|
+
# +::MyModule+, then Object is returned.
|
20
|
+
def namespace_module
|
21
|
+
namespace_name = name.split('::')[0..-2].join('::')
|
22
|
+
namespace_name.empty? ? Object : namespace_name.constantize
|
23
|
+
end
|
24
|
+
|
25
|
+
# Gets the "dirname" of a "module path" (the string/symbol representing the namespace modules that it is contained in),
|
26
|
+
# in the same sense that <tt>File.dirname</tt> returns the dirname of a _filesystem_ path.
|
27
|
+
#
|
28
|
+
# Same as +namespace_of+, only this just returns the _name_ of the namespace module (as a string), rather than returning the
|
29
|
+
# constant itself.
|
30
|
+
#
|
31
|
+
# See also <tt>Module.basename</tt>
|
32
|
+
def self.dirname(module_or_name)
|
33
|
+
case module_or_name
|
34
|
+
when Module
|
35
|
+
module_or_name.namespace_module.name
|
36
|
+
when Symbol
|
37
|
+
Module.split_name(module_or_name)[0..-2].join('::')
|
38
|
+
when String
|
39
|
+
Module.split_name(module_or_name)[0..-2].join('::')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
class << self
|
43
|
+
alias_method :namespace_name_of, :dirname
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.namespace_of(module_or_name)
|
47
|
+
namespace_name_of(module_or_name).constantize
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
# _____ _
|
55
|
+
# |_ _|__ ___| |_
|
56
|
+
# | |/ _ \/ __| __|
|
57
|
+
# | | __/\__ \ |_
|
58
|
+
# |_|\___||___/\__|
|
59
|
+
#
|
60
|
+
=begin test
|
61
|
+
require 'test/unit'
|
62
|
+
|
63
|
+
module OuterModule; end
|
64
|
+
module OuterModule::MiddleModule; end
|
65
|
+
module OuterModule::MiddleModule::InnerModule; end
|
66
|
+
|
67
|
+
class NamespaceTest < Test::Unit::TestCase
|
68
|
+
module InnerModule; end
|
69
|
+
def test_1
|
70
|
+
assert_equal Object, OuterModule.namespace_module
|
71
|
+
end
|
72
|
+
def test_nesting
|
73
|
+
assert_equal OuterModule::MiddleModule,
|
74
|
+
OuterModule::MiddleModule::InnerModule.namespace_module
|
75
|
+
end
|
76
|
+
def test_nesting_2
|
77
|
+
assert_equal NamespaceTest, InnerModule.namespace_module
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class NamespaceOfTest < Test::Unit::TestCase
|
82
|
+
module InnerModule; end
|
83
|
+
def test_1
|
84
|
+
assert_equal Object, Module.namespace_of(OuterModule)
|
85
|
+
end
|
86
|
+
def test_nesting
|
87
|
+
assert_equal OuterModule::MiddleModule,
|
88
|
+
Module.namespace_of(OuterModule::MiddleModule::InnerModule)
|
89
|
+
assert_equal OuterModule::MiddleModule,
|
90
|
+
Module.namespace_of(:'OuterModule::MiddleModule::InnerModule')
|
91
|
+
assert_equal OuterModule::MiddleModule,
|
92
|
+
Module.namespace_of('OuterModule::MiddleModule::InnerModule')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class NamespaceNameOfTest < Test::Unit::TestCase
|
97
|
+
module InnerModule; end
|
98
|
+
def test_1
|
99
|
+
assert_equal 'Object',
|
100
|
+
Module.namespace_name_of(OuterModule)
|
101
|
+
end
|
102
|
+
def test_nesting
|
103
|
+
assert_equal 'OuterModule::MiddleModule',
|
104
|
+
Module.namespace_name_of(OuterModule::MiddleModule::InnerModule)
|
105
|
+
assert_equal 'OuterModule::MiddleModule',
|
106
|
+
Module.namespace_name_of(:'OuterModule::MiddleModule::InnerModule')
|
107
|
+
assert_equal 'OuterModule::MiddleModule',
|
108
|
+
Module.namespace_name_of('OuterModule::MiddleModule::InnerModule')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
=end
|
112
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) ActiveSupport authors
|
4
|
+
# License::
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
# Developer notes::
|
7
|
+
# * Tests incomplete...
|
8
|
+
# Changes::
|
9
|
+
# * Copied from ActiveSupport.
|
10
|
+
#++
|
11
|
+
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'facets/core/kernel/constant'
|
15
|
+
|
16
|
+
|
17
|
+
class Module
|
18
|
+
# Return all the parents of this module, ordered from nested outwards. The
|
19
|
+
# receiver is not contained within the result.
|
20
|
+
def parents
|
21
|
+
parents = []
|
22
|
+
parts = name.split('::')[0..-2]
|
23
|
+
until parts.empty?
|
24
|
+
#parents << (parts * '::').constantize
|
25
|
+
parents << constant(parts * '::')
|
26
|
+
parts.pop
|
27
|
+
end
|
28
|
+
parents << Object unless parents.include? Object
|
29
|
+
parents
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
# _____ _
|
37
|
+
# |_ _|__ ___| |_
|
38
|
+
# | |/ _ \/ __| __|
|
39
|
+
# | | __/\__ \ |_
|
40
|
+
# |_|\___||___/\__|
|
41
|
+
#
|
42
|
+
=begin test
|
43
|
+
require 'test/unit'
|
44
|
+
|
45
|
+
module OuterModule; end
|
46
|
+
module OuterModule::InnerModule; end
|
47
|
+
|
48
|
+
class TheTest < Test::Unit::TestCase
|
49
|
+
module InnerModule; end
|
50
|
+
def test_1
|
51
|
+
assert_equal [Object], OuterModule.parents
|
52
|
+
end
|
53
|
+
def test_nesting
|
54
|
+
assert_equal [OuterModule, Object], OuterModule::InnerModule.parents
|
55
|
+
end
|
56
|
+
def test_nesting_2
|
57
|
+
assert_equal [TheTest, Object], InnerModule.parents
|
58
|
+
end
|
59
|
+
end
|
60
|
+
=end
|
61
|
+
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
# Developer notes::
|
7
|
+
#++
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'qualitysmith_extensions/object/ignore_access'
|
11
|
+
require 'qualitysmith_extensions/module/split'
|
12
|
+
require 'facets/core/module/by_name'
|
13
|
+
require 'facets/core/module/modspace'
|
14
|
+
|
15
|
+
module Kernel
|
16
|
+
# This is similar to +Kernel#remove_const+, but it _only_ works for modules/classes.
|
17
|
+
#
|
18
|
+
# This is similar to the built-in <tt>Module#remove_module</tt>, but it lets you do it in a more object oriented manner,
|
19
|
+
# calling +remove!+ on the module/class/constant itself that you want to remove, rather than on its parent.
|
20
|
+
#
|
21
|
+
# Makes it possible to write simply:
|
22
|
+
# A::B::C.remove_const!
|
23
|
+
# rather than having to think about which module the constant is actually defined in and calling +remove_const+ on that module.
|
24
|
+
# This is how you would have to otherwise do it:
|
25
|
+
# A::B.send(:remove_const, :C)
|
26
|
+
#
|
27
|
+
def remove_const!
|
28
|
+
if split.size > 1
|
29
|
+
parent_module = modspace # For example, would be A::B for A::B::C
|
30
|
+
const_to_remove = split.last # For example, would be :C for A::B::C
|
31
|
+
parent_module.ignore_access.remove_const(const_to_remove)
|
32
|
+
else
|
33
|
+
Object.ignore_access.remove_const(name)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# _____ _
|
39
|
+
# |_ _|__ ___| |_
|
40
|
+
# | |/ _ \/ __| __|
|
41
|
+
# | | __/\__ \ |_
|
42
|
+
# |_|\___||___/\__|
|
43
|
+
#
|
44
|
+
=begin test
|
45
|
+
require 'test/unit'
|
46
|
+
require 'qualitysmith_extensions/kernel/remove_const' # Test for compatibility. Just in case the remove_const_before_was_added_to_Kernel alias might have thrown something off.
|
47
|
+
|
48
|
+
# How it would be done *without* this extension:
|
49
|
+
module TestRemoveABC_TheOldWay
|
50
|
+
module A
|
51
|
+
module B
|
52
|
+
class C
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class TheTest < Test::Unit::TestCase
|
58
|
+
def test_1
|
59
|
+
assert_nothing_raised { A::B::C }
|
60
|
+
A::B.send(:remove_const, :C)
|
61
|
+
assert_raise(NameError) { A::B::C }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# How it would be done *with* this extension:
|
67
|
+
module TestRemoveABC
|
68
|
+
module A
|
69
|
+
module B
|
70
|
+
class C
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class TheTest < Test::Unit::TestCase
|
76
|
+
def test_1
|
77
|
+
assert_nothing_raised { A::B::C }
|
78
|
+
A::B::C.remove_const!
|
79
|
+
assert_raise(NameError) { A::B::C }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
module TestRemoveAB
|
85
|
+
module A
|
86
|
+
module B
|
87
|
+
module C
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class TheTest < Test::Unit::TestCase
|
93
|
+
def test_1
|
94
|
+
assert_nothing_raised { A::B }
|
95
|
+
A::B.remove_const!
|
96
|
+
assert_raise(NameError) { A::B }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
module A
|
102
|
+
end
|
103
|
+
module TestRemoveA_FromObject
|
104
|
+
|
105
|
+
class TheTest < Test::Unit::TestCase
|
106
|
+
def test_1
|
107
|
+
assert_nothing_raised { A }
|
108
|
+
A.remove_const!
|
109
|
+
assert_raise(NameError) { A }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
=end
|
115
|
+
|
116
|
+
|
117
|
+
|