kyanite 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Div +6 -32
- data/{History.txt → History.rdoc} +8 -0
- data/{License.txt → License.rdoc} +0 -0
- data/Manifest.txt +6 -21
- data/README.rdoc +44 -0
- data/Rakefile.rb +19 -68
- data/console.rb +2 -4
- data/lib/kyanite.rb +151 -14
- data/lib/kyanite/array.rb +127 -4
- data/lib/kyanite/basics.rb +3 -7
- data/lib/kyanite/dictionary.rb +19 -21
- data/lib/kyanite/enumerable/enumerable_enumerables.rb +22 -24
- data/lib/kyanite/enumerable/enumerable_numerics.rb +51 -49
- data/lib/kyanite/enumerable/enumerable_strings.rb +18 -25
- data/lib/kyanite/enumerable/structure.rb +46 -58
- data/lib/kyanite/general/callerutils.rb +30 -28
- data/lib/kyanite/general/classutils.rb +73 -63
- data/lib/kyanite/general/kernel.rb +45 -64
- data/lib/kyanite/general/object.rb +22 -46
- data/lib/kyanite/general/true_false.rb +33 -27
- data/lib/kyanite/general/undoable.rb +12 -16
- data/lib/kyanite/hash.rb +63 -58
- data/lib/kyanite/numeric.rb +14 -1
- data/lib/kyanite/numeric/float.rb +32 -22
- data/lib/kyanite/numeric/integer.rb +12 -20
- data/lib/kyanite/optimizer.rb +41 -24
- data/lib/kyanite/range.rb +42 -22
- data/lib/kyanite/set.rb +56 -63
- data/lib/kyanite/string.rb +1 -2
- data/lib/kyanite/string/cast.rb +61 -37
- data/lib/kyanite/string/chars.rb +66 -36
- data/lib/kyanite/string/chars_const.rb +4 -3
- data/lib/kyanite/string/diff.rb +64 -34
- data/lib/kyanite/string/include.rb +16 -9
- data/lib/kyanite/string/list.rb +38 -8
- data/lib/kyanite/string/misc.rb +64 -0
- data/lib/kyanite/string/nested.rb +39 -22
- data/lib/kyanite/string/random.rb +117 -47
- data/lib/kyanite/string/split.rb +84 -45
- data/lib/kyanite/symbol.rb +30 -21
- data/lib/kyanite/tree.rb +33 -28
- data/test/_start_all.rb +18 -15
- data/test/array/test_array.rb +5 -7
- data/test/enumerable/test_enumerable_enumerables.rb +11 -15
- data/test/enumerable/test_enumerable_numerics.rb +50 -54
- data/test/enumerable/test_enumerable_strings.rb +8 -11
- data/test/enumerable/test_structure.rb +6 -8
- data/test/general/test_classutils.rb +9 -9
- data/test/general/test_object.rb +4 -5
- data/test/general/test_true_false.rb +4 -5
- data/test/numeric/test_numeric_integer.rb +6 -6
- data/test/string/test_cast.rb +4 -5
- data/test/string/test_chars.rb +6 -7
- data/test/string/test_diff.rb +4 -5
- data/test/string/test_list.rb +4 -5
- data/test/string/test_misc.rb +58 -0
- data/test/string/test_nested.rb +4 -5
- data/test/string/test_split.rb +10 -5
- data/test/test_dictionary.rb +4 -6
- data/test/test_hash.rb +5 -7
- data/test/test_optimizer.rb +4 -5
- data/test/test_range.rb +8 -9
- data/test/test_set.rb +7 -7
- data/test/test_tree.rb +7 -10
- data/version.rb +8 -0
- metadata +32 -33
- data/README.txt +0 -47
- data/lib/kyanite/array/array.rb +0 -140
- data/lib/kyanite/array/array2.rb +0 -142
- data/lib/kyanite/array/matrix2.rb +0 -120
- data/lib/kyanite/hoe.rb +0 -2
- data/lib/kyanite/matrix2.rb +0 -2
- data/lib/kyanite/numeric/numeric.rb +0 -54
- data/lib/kyanite/operation.rb +0 -5
- data/lib/kyanite/operation/call_tracker.rb +0 -69
- data/lib/kyanite/operation/hoe.rb +0 -12
- data/lib/kyanite/operation/rake.rb +0 -298
- data/lib/kyanite/operation/regexp.rb +0 -28
- data/lib/kyanite/operation/unit_test.rb +0 -50
- data/lib/kyanite/rake.rb +0 -2
- data/lib/kyanite/smart_load_path.rb +0 -6
- data/lib/kyanite/string/div.rb +0 -28
- data/lib/kyanite/string/mgsub.rb +0 -43
- data/lib/kyanite/unit_test.rb +0 -2
- data/test/array/test_matrix2.rb +0 -166
- data/test/string/test_mgsub.rb +0 -58
@@ -1,24 +1,20 @@
|
|
1
|
-
# ruby encoding: utf-8
|
1
|
+
# ruby encoding: utf-8
|
2
2
|
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
3
8
|
|
4
|
-
# [ | Kyanite | Object | Array | Set | *Enumerable* | Hash | ] | Enumerable | EnumerableNumerics | *EnumerableStrings* | EnumerableEnumerables |
|
5
|
-
# ---
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# == *Enumeration* *Of* *Strings*
|
9
|
-
# See TestKyaniteEnumerableStrings for tests and examples.
|
10
|
-
# See ArrayOfStrings for an Array with modul EnumerableStrings included.
|
11
|
-
#
|
12
|
-
#
|
13
|
-
module EnumerableStrings
|
14
9
|
|
15
10
|
|
16
|
-
|
11
|
+
# @!macro enum_of_strings
|
12
|
+
module EnumerableStrings
|
13
|
+
|
14
|
+
# Delete every element from the front with is identical with the back -- leave the significant middle part.
|
15
|
+
# Example:
|
17
16
|
# ['lut', 'lutm', 'lutmi', 'lutmil', 'lutmila', 'lutrika', 'lutrik', 'lutri', 'lutr', 'lut'].palindrom_rumpf =>
|
18
17
|
# ['lutm', 'lutmi', 'lutmil', 'lutmila', 'lutrika', 'lutrik', 'lutri', 'lutr']
|
19
|
-
# d.h. vorne und hinten wird alles Gleiche weggestrichen.
|
20
|
-
#
|
21
|
-
# Tests and examples see TestKyaniteEnumerableStrings.
|
22
18
|
#
|
23
19
|
def palindrom_rumpf
|
24
20
|
result = self.dup
|
@@ -38,26 +34,23 @@ end
|
|
38
34
|
|
39
35
|
|
40
36
|
|
41
|
-
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# == *Array* *Of* *Strings*
|
46
|
-
# An ArrayOfstrings is an Array with modul EnumerableStrings included.
|
47
|
-
# See TestKyaniteEnumerableStrings for tests and examples.
|
48
|
-
#
|
37
|
+
|
38
|
+
# @!macro enum_of_strings
|
49
39
|
class ArrayOfStrings < Array
|
50
40
|
include EnumerableStrings
|
51
41
|
end
|
52
42
|
|
53
|
-
|
43
|
+
|
54
44
|
|
55
45
|
class Array
|
56
46
|
|
57
|
-
#
|
47
|
+
# @!group Cast
|
48
|
+
# Returns {ArrayOfStrings} (this is an {Array} with modul {EnumerableStrings} included)
|
49
|
+
# @return [ArrayOfStrings]
|
58
50
|
def to_array_of_strings
|
59
51
|
ArrayOfStrings.new(self)
|
60
52
|
end
|
53
|
+
#@!endgroup
|
61
54
|
|
62
55
|
end
|
63
56
|
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
-
|
2
|
+
|
3
3
|
if $0 == __FILE__
|
4
|
-
require
|
5
|
-
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
6
|
end
|
7
7
|
|
8
|
+
|
8
9
|
require 'kyanite/general/object'
|
9
10
|
require 'kyanite/array/array'
|
10
11
|
require 'kyanite/dictionary'
|
@@ -14,73 +15,63 @@ require 'kyanite/dictionary'
|
|
14
15
|
|
15
16
|
class Object
|
16
17
|
|
17
|
-
#
|
18
|
-
# String
|
19
|
-
#
|
18
|
+
# @!macro [new] is_collection
|
19
|
+
# -- Defined for all objects: Do I contain multiple objects? {String} and {Range} are not considered as collection.
|
20
|
+
#
|
21
|
+
# Tests and examples {TestKyaniteEnumerableStructure#test_is_collection here}.
|
22
|
+
|
23
|
+
# +false+
|
24
|
+
# @!macro is_collection
|
25
|
+
# @return [false]
|
20
26
|
def is_collection?; false; end
|
21
27
|
|
22
28
|
end
|
23
29
|
|
24
30
|
|
25
|
-
|
31
|
+
class Range
|
26
32
|
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
|
31
|
-
def is_collection?; true; end
|
33
|
+
# +false+
|
34
|
+
# @!macro is_collection
|
35
|
+
# @return [false]
|
36
|
+
def is_collection?; false; end
|
32
37
|
|
33
38
|
end
|
34
39
|
|
35
40
|
|
36
|
-
class String
|
37
41
|
|
38
|
-
|
39
|
-
# :section: Structure
|
40
|
-
#
|
42
|
+
class String
|
41
43
|
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
44
|
+
# @!group Miscellaneous
|
45
|
+
# +false+
|
46
|
+
# @!macro is_collection
|
47
|
+
# @return [false]
|
46
48
|
def is_collection?; false; end
|
47
|
-
|
48
|
-
|
49
|
+
# @!endgroup
|
49
50
|
end
|
50
51
|
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
# Enthält ein Objekt mehrere Objekte?
|
55
|
-
# Rückgabe: false
|
56
|
-
# String und Range gelten nicht als Collection.
|
57
|
-
# See TestKyaniteEnumerableStructure for tests and examples.
|
58
|
-
def is_collection?; false; end
|
53
|
+
# @!group Structure Reflection
|
59
54
|
|
60
|
-
|
61
|
-
|
55
|
+
module Enumerable
|
62
56
|
|
57
|
+
# @!macro is_collection
|
58
|
+
# +true+
|
59
|
+
# @!macro is_collection
|
60
|
+
# @return [true]
|
61
|
+
def is_collection?; true; end
|
62
|
+
|
63
|
+
end
|
63
64
|
|
64
65
|
|
65
66
|
|
66
67
|
|
67
68
|
|
68
|
-
#
|
69
|
-
# ---
|
70
|
-
#
|
71
|
-
#
|
72
|
-
# == *General* *Enumerations*
|
73
|
-
# See TestKyaniteEnumerableStructure for tests and examples.
|
74
|
-
#
|
75
|
-
#
|
69
|
+
# @!macro enumerable
|
76
70
|
module Enumerable
|
77
71
|
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
# die Methode gibt es auch als Hash#distribution.
|
82
|
-
# See TestKyaniteEnumerableStructure for tests and examples.
|
83
|
-
#
|
72
|
+
# Returns the distribution of +size+, +class+ or any other characteristics of the enumerated elements.
|
73
|
+
# See also {Hash#distribution}. Tests and examples {TestKyaniteEnumerableStructure#test_distribution_class here}.
|
74
|
+
# @return [Array]
|
84
75
|
def distribution( mode = :size)
|
85
76
|
verteilung = Hash.new
|
86
77
|
each do | element |
|
@@ -96,20 +87,17 @@ module Enumerable
|
|
96
87
|
|
97
88
|
|
98
89
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
# :precision => :all alle Elemente werden geprüft
|
109
|
-
# :ignore_nil => true NilClass wird nicht aufgeführt (STANDARD)
|
110
|
-
# :ignore_nil => false NilClass wird mit aufgeführt
|
90
|
+
# What kind of objects contains the collection?
|
91
|
+
# Returns the class of content elements, or +Object+ if there are several.
|
92
|
+
#
|
93
|
+
# Parameters is the accuracy with which the content is checked.
|
94
|
+
# [:precision => 1] only the first element is checked
|
95
|
+
# [:precision => 2] the first and the last elements are checked (STANDARD)
|
96
|
+
# [:precision => :all] every element is checked
|
97
|
+
# [:ignore_nil => true] NilClass will not be listed (STANDARD)
|
98
|
+
# [:ignore_nil => false] NilClass will be listed
|
111
99
|
#
|
112
|
-
#
|
100
|
+
# Tests and examples {TestKyaniteEnumerableStructure#test_contentclass_mono here}.
|
113
101
|
#
|
114
102
|
def contentclass( options={} )
|
115
103
|
precision = options[:precision] || 2
|
@@ -1,30 +1,31 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
2
8
|
require 'kyanite/string/include'
|
3
9
|
|
4
10
|
|
5
11
|
|
6
|
-
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# ---
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# == *Tools* *for* Kernel#caller
|
13
|
-
#
|
12
|
+
|
13
|
+
# @!macro caller_utils
|
14
14
|
class CallerUtils
|
15
15
|
|
16
|
-
#
|
16
|
+
# Examines the call stack, returns the size of the stack, or the last caller.
|
17
|
+
# @param options [Hash] Options
|
18
|
+
# @option options [String, Array] :skip Ignore caller that contain the specified fragment
|
19
|
+
# @option options [Symbol] :mode What kind of result is to be returned? +:caller+ (default) returns the caller, +:size+ returns the size of the call stack.
|
17
20
|
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# :caller (Standard) liefert den Caller,
|
22
|
-
# :size liefert die Größe das Call-Stacks
|
21
|
+
# Example:
|
22
|
+
# CallerUtils.mycaller(:skip => ['ruby\gems', 'ruby/gems', 'test/unit'])
|
23
|
+
# => "C:/Ruby-Projekte/kyanite/lib/kyanite/general/callerutils.rb:110:in `<main>'"
|
23
24
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
25
|
+
# CallerUtils.mycaller(:skip => ['ruby\gems', 'ruby/gems', 'test/unit'], :mode=> :size)
|
26
|
+
# => 1
|
27
|
+
#
|
28
|
+
# @return [String, Integer]
|
28
29
|
def self.mycaller(options={})
|
29
30
|
skip = options[:skip] || []
|
30
31
|
skip = [skip] if skip.kind_of?(String)
|
@@ -53,14 +54,14 @@ class CallerUtils
|
|
53
54
|
|
54
55
|
|
55
56
|
|
56
|
-
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# my_caller = CallerUtils.mycaller(:skip => ['perception', 'ruby\gems', 'ruby/gems', 'test/unit'])
|
57
|
+
|
58
|
+
# Determines the root directory of a caller on heuristic way. The name of the main directory is usually the name of the application or library.
|
59
|
+
# Example:
|
60
|
+
# my_caller = CallerUtils.mycaller(:skip => ['ruby\gems', 'ruby/gems', 'test/unit'])
|
61
61
|
# CallerUtils.mycaller_maindir(my_caller)
|
62
|
-
# => "
|
62
|
+
# => "C:/Ruby-Projekte/kyanite"
|
63
63
|
#
|
64
|
+
# @return [String]
|
64
65
|
def self.mycaller_maindir(mycaller)
|
65
66
|
dir_caller =File.dirname(mycaller)
|
66
67
|
array_caller = dir_caller.split('/')
|
@@ -109,10 +110,11 @@ if $0 == __FILE__
|
|
109
110
|
|
110
111
|
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
|
114
|
+
my_caller = CallerUtils.mycaller(:skip => ['ruby\gems', 'ruby/gems', 'test/unit'])
|
115
|
+
#puts my_caller
|
116
|
+
puts CallerUtils.mycaller_maindir(my_caller) if my_caller
|
117
|
+
|
116
118
|
|
117
119
|
|
118
120
|
|
@@ -1,26 +1,34 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
2
8
|
|
3
|
-
|
4
|
-
require 'facets/class/descendants' # Methode descendants
|
9
|
+
# @!group Class Utils
|
5
10
|
|
11
|
+
require 'facets/class/descendants' # Methode descendants
|
12
|
+
# require 'facets/kernel/singleton_class' # Easy access to an object‘s "special" class, otherwise known as it‘s eigen or meta class.
|
6
13
|
|
7
|
-
#
|
8
|
-
# [ ] | Object | KKernel | CallerUtils | Undoable | *Class* |
|
14
|
+
# =================================================================================================================
|
9
15
|
#
|
10
|
-
#
|
16
|
+
# @!macro class_utils
|
11
17
|
#
|
12
|
-
#
|
13
|
-
#
|
18
|
+
# === Added from {http://rubyworks.github.com/rubyfaux/?doc=http://rubyworks.github.com/facets/docs/facets-2.9.3/core.json#api-class-Class Facets Class}:
|
19
|
+
# [+descendants(generations=-1))+] List all descedents of this class.
|
14
20
|
#
|
15
21
|
class Class
|
16
22
|
|
17
|
-
#
|
23
|
+
# Comparison operator (alphabetical)
|
24
|
+
# @return [Integer] 1, 0, -1
|
18
25
|
def <=>(other)
|
19
26
|
( ( self.to_s ) <=> ( other.to_s ) )
|
20
27
|
end
|
21
28
|
|
22
29
|
|
23
|
-
#
|
30
|
+
# Fuzzy comparison of two classes (useful for tests)
|
31
|
+
# @return [Boolean]
|
24
32
|
def =~(other)
|
25
33
|
return true if self == other
|
26
34
|
return true if self.descendants.include?(other)
|
@@ -28,21 +36,13 @@ class Class
|
|
28
36
|
return false
|
29
37
|
end
|
30
38
|
|
31
|
-
#
|
32
|
-
# Die Methode gibt es insbesondere für String und Symbol, siehe String#to_class, Symbol#to_class
|
33
|
-
# Für Class ist sie einfach transparent, d.h. sie liefert self.
|
34
|
-
# Tests and examples see TestKyaniteClassutils
|
35
|
-
#
|
39
|
+
# (see String#to_class)
|
36
40
|
def to_class
|
37
41
|
self
|
38
42
|
end
|
39
43
|
|
40
44
|
|
41
|
-
#
|
42
|
-
# Wandelt eine Klasse in einen Klassennamen um, der nur Kleinbuchstaben enthält.
|
43
|
-
# Siehe String#to_classname, Symbol#to_classname
|
44
|
-
# Tests and examples see TestKyaniteClassutils
|
45
|
-
#
|
45
|
+
# (see String#to_classname)
|
46
46
|
def to_classname
|
47
47
|
self.to_s.demodulize.underscore
|
48
48
|
end
|
@@ -52,58 +52,32 @@ end # class
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
class Symbol
|
58
|
-
|
59
|
-
# Wandelt ein Symbol in einen Klassennamen, der nur Kleinbuchstaben enthält.
|
60
|
-
# Siehe String#to_classname
|
61
|
-
# Tests and examples see TestKyaniteClassutils
|
62
|
-
#
|
63
|
-
def to_classname
|
64
|
-
self.to_s.to_classname
|
65
|
-
end
|
66
|
-
|
67
|
-
# Wandelt einen Klassennamen in eine Klasse.
|
68
|
-
# Akzeptiert sowohl CamelCase als auch down_case.
|
69
|
-
# Die Methode gibt es auch für String und Class.
|
70
|
-
# Tests and examples see TestKyaniteClassutils
|
71
|
-
#
|
72
|
-
def to_class
|
73
|
-
self.to_s.to_class
|
74
|
-
end
|
75
|
-
|
76
|
-
end # class
|
55
|
+
|
77
56
|
|
78
57
|
|
58
|
+
class String
|
79
59
|
|
80
60
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
class String
|
85
61
|
|
86
|
-
#
|
87
|
-
# :section: Class Utils
|
88
|
-
# See TestKyaniteClassutils for tests and examples.
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
# Wandelt einen String in einen Klassennamen, der nur Kleinbuchstaben enthält.
|
93
|
-
# 'MeinModul::EineKlasse' => 'eine_klasse'
|
62
|
+
# Converts to a class name , the reverse of {String#to_class to_class}.
|
94
63
|
#
|
95
|
-
#
|
64
|
+
# classes {Class}, {Symbol}, {String}. The class name will contain only lowercase letters.
|
65
|
+
# 'MyModul::MyClass' => 'my_class'
|
66
|
+
#
|
67
|
+
# Tests and examples {TestKyaniteClassutils here}.
|
68
|
+
# @return [String]
|
96
69
|
#
|
97
70
|
def to_classname
|
98
71
|
self.demodulize.underscore
|
99
72
|
end
|
100
73
|
|
101
74
|
|
102
|
-
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
# Tests and examples
|
75
|
+
# Converts to a class, the reverse of {String#to_classname to_classname}
|
76
|
+
#
|
77
|
+
# Defined for classes {Class}, {Symbol}, {String}. Accepts both CamelCase and down_case.
|
78
|
+
#
|
79
|
+
# Tests and examples {TestKyaniteClassutils here}.
|
80
|
+
# @return [Class]
|
107
81
|
#
|
108
82
|
def to_class
|
109
83
|
self.camelize.constantize
|
@@ -122,6 +96,7 @@ class String
|
|
122
96
|
# "ActiveRecord::Errors".underscore # => active_record/errors
|
123
97
|
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson. See License.txt.
|
124
98
|
#
|
99
|
+
# @return [String]
|
125
100
|
def underscore
|
126
101
|
self.gsub(/::/, '/').
|
127
102
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
@@ -144,6 +119,7 @@ class String
|
|
144
119
|
# "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
|
145
120
|
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson. See License.txt.
|
146
121
|
#
|
122
|
+
# @return [String]
|
147
123
|
def camelize(first_letter_in_uppercase = true)
|
148
124
|
if first_letter_in_uppercase
|
149
125
|
self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
@@ -160,6 +136,7 @@ class String
|
|
160
136
|
# "Inflections".demodulize # => "Inflections"
|
161
137
|
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson. See License.txt.
|
162
138
|
#
|
139
|
+
# @return [String]
|
163
140
|
def demodulize
|
164
141
|
self.gsub(/^.*::/, '')
|
165
142
|
end
|
@@ -185,6 +162,7 @@ class String
|
|
185
162
|
# unknown.
|
186
163
|
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson. See License.txt.
|
187
164
|
#
|
165
|
+
# @return [Class]
|
188
166
|
def constantize
|
189
167
|
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
|
190
168
|
raise NameError, "#{self.inspect} is not a valid constant name!"
|
@@ -193,14 +171,46 @@ class String
|
|
193
171
|
Object.module_eval("::#{$1}", __FILE__, __LINE__)
|
194
172
|
end
|
195
173
|
|
196
|
-
end #
|
174
|
+
end # String
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
197
181
|
|
198
|
-
|
182
|
+
# =================================================================================================================
|
183
|
+
#
|
184
|
+
# @!macro class_utils
|
185
|
+
#
|
186
|
+
class Symbol
|
187
|
+
|
188
|
+
# (see String#to_classname)
|
189
|
+
def to_classname
|
190
|
+
self.to_s.to_classname
|
191
|
+
end
|
192
|
+
|
193
|
+
# (see String#to_class)
|
194
|
+
def to_class
|
195
|
+
self.to_s.to_class
|
196
|
+
end
|
197
|
+
|
198
|
+
end # Symbol
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
# =================================================================================================================
|
205
|
+
# @!macro class_utils
|
206
|
+
#
|
199
207
|
class NilClass
|
200
208
|
|
201
|
-
#
|
209
|
+
# @return [String] empty String
|
202
210
|
def to_classname; ''; end
|
203
211
|
|
212
|
+
# @!group return nil
|
213
|
+
|
204
214
|
def camelize; nil; end
|
205
215
|
def constantize; nil; end
|
206
216
|
def demodulize; nil; end
|
@@ -208,7 +218,7 @@ if defined? TransparentNil
|
|
208
218
|
def underscore; nil; end
|
209
219
|
|
210
220
|
end
|
211
|
-
|
221
|
+
|
212
222
|
|
213
223
|
|
214
224
|
|