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
data/lib/kyanite/string.rb
CHANGED
@@ -4,10 +4,9 @@ require 'kyanite/enumerable'
|
|
4
4
|
require 'kyanite/string/cast'
|
5
5
|
require 'kyanite/string/chars'
|
6
6
|
require 'kyanite/string/diff'
|
7
|
-
require 'kyanite/string/div'
|
8
7
|
require 'kyanite/string/include'
|
9
8
|
require 'kyanite/string/list'
|
10
|
-
require 'kyanite/string/
|
9
|
+
require 'kyanite/string/misc'
|
11
10
|
require 'kyanite/string/nested'
|
12
11
|
require 'kyanite/string/random'
|
13
12
|
require 'kyanite/string/split'
|
data/lib/kyanite/string/cast.rb
CHANGED
@@ -1,35 +1,33 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
2
8
|
require 'kyanite/numeric/integer'
|
3
9
|
|
4
|
-
# [ | Kyanite | *Object* | Array | Set | Enumerable | Hash | ] | Object | *String* | Symbol | Numeric |
|
5
|
-
#
|
6
|
-
# ---
|
7
|
-
#
|
8
|
-
# == *String*
|
9
|
-
#
|
10
|
-
#
|
11
|
-
class String
|
12
10
|
|
13
|
-
|
14
|
-
# :section: Cast
|
15
|
-
# See TestKyaniteStringCast for tests and examples.
|
16
|
-
#
|
11
|
+
class String
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
#
|
13
|
+
|
14
|
+
# @!group Cast
|
15
|
+
|
16
|
+
# Converts a string into the most plausible Identifier
|
22
17
|
#
|
23
|
-
#
|
18
|
+
# See examples and tests {TestKyaniteStringCast#test_to_identifier here}.
|
19
|
+
# @return [Integer]
|
24
20
|
def to_identifier
|
25
21
|
self.strip.to_integer_optional
|
26
22
|
end
|
27
23
|
|
28
24
|
|
29
|
-
|
30
|
-
#
|
25
|
+
|
26
|
+
# Converts a string to an integer, even if the number was appended to anything.
|
27
|
+
# Unlike +to_i+ it returns +nil+ if no integer was found inside the string.
|
31
28
|
#
|
32
|
-
#
|
29
|
+
# See examples and tests {TestKyaniteStringCast#test_to_integer here}.
|
30
|
+
# @return [Integer]
|
33
31
|
def to_integer
|
34
32
|
return nil unless self =~ /\d/
|
35
33
|
firsttry = self.to_i
|
@@ -38,18 +36,23 @@ class String
|
|
38
36
|
end
|
39
37
|
|
40
38
|
|
41
|
-
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
39
|
+
|
40
|
+
# Tries to convert a string to an integer.
|
41
|
+
# Returns +self+ if the string does not start with a number.
|
42
|
+
# Empty strings are converted to +nil+.
|
43
|
+
#
|
44
|
+
# See examples and tests {TestKyaniteStringCast#test_to_integer_optional here}.
|
45
|
+
# @return [Integer, String]
|
46
46
|
def to_integer_optional
|
47
47
|
return nil if self.empty?
|
48
48
|
return self unless (self =~ /^\d/ || self =~ /^-\d/ )
|
49
49
|
return self.to_i
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
|
53
|
+
# Non-empty strings are returned.
|
54
|
+
# Empty strings are converted to +nil+.
|
55
|
+
# @return [String, Nil]
|
53
56
|
def to_nil
|
54
57
|
return self unless self.empty?
|
55
58
|
nil
|
@@ -59,12 +62,14 @@ class String
|
|
59
62
|
|
60
63
|
|
61
64
|
unless defined? HEX_CHARS
|
65
|
+
# @private
|
62
66
|
HEX_CHARS = '0123456789abcdef'.freeze
|
63
67
|
end
|
64
68
|
|
65
69
|
|
66
70
|
# Get a hex representation for a char.
|
67
|
-
# See also
|
71
|
+
# See also {#from_x from_x}.
|
72
|
+
# @return [String]
|
68
73
|
def to_x
|
69
74
|
hex = ''
|
70
75
|
each_byte { |byte|
|
@@ -76,8 +81,11 @@ class String
|
|
76
81
|
hex
|
77
82
|
end
|
78
83
|
|
84
|
+
|
85
|
+
|
79
86
|
# Get a char for a hex representation.
|
80
|
-
# See also
|
87
|
+
# See also {#to_x to_x}.
|
88
|
+
# @return [String]
|
81
89
|
def from_x
|
82
90
|
str, q, first = '', 0, false
|
83
91
|
each_byte { |byte|
|
@@ -100,16 +108,32 @@ class String
|
|
100
108
|
|
101
109
|
end
|
102
110
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
111
|
+
|
112
|
+
# @!endgroup
|
113
|
+
|
114
|
+
class NilClass
|
115
|
+
def to_identifier; nil; end
|
116
|
+
def to_integer; nil; end
|
117
|
+
def to_integer_optional; nil; end
|
118
|
+
def to_nil(*a); nil; end
|
119
|
+
def to_x; nil; end
|
120
|
+
def from_x; nil; end
|
112
121
|
end
|
113
122
|
|
114
123
|
|
124
|
+
class Integer
|
125
|
+
|
126
|
+
|
127
|
+
# +self+, complements {String#to_integer}.
|
128
|
+
# @return [self]
|
129
|
+
def to_integer; self; end
|
130
|
+
|
131
|
+
|
132
|
+
# +self+, complements {String#to_integer_optional}.
|
133
|
+
# @return [self]
|
134
|
+
def to_integer_optional; self; end
|
135
|
+
|
136
|
+
|
137
|
+
end # class
|
138
|
+
|
115
139
|
|
data/lib/kyanite/string/chars.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
# ü
|
2
3
|
if $0 == __FILE__
|
3
|
-
require
|
4
|
-
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
5
6
|
end
|
6
7
|
|
8
|
+
|
7
9
|
require 'kyanite/string/chars_const'
|
8
10
|
|
9
|
-
|
10
|
-
unless defined? MYSQL_REPLACES
|
11
|
-
MYSQL_REPLACES = [
|
12
|
-
[/ä/, 'a'],
|
13
|
-
[/ö/, 'o'],
|
14
|
-
[/ü/, 'u'],
|
15
|
-
[/Ä/, 'a'],
|
16
|
-
[/Ö/, 'o'],
|
17
|
-
[/Ü/, 'u'],
|
18
|
-
[/ss/, 'ß'],
|
19
|
-
[/SS/, 'ß']
|
20
|
-
]
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
|
26
12
|
|
27
13
|
|
28
14
|
class String
|
29
15
|
|
16
|
+
unless defined? MYSQL_REPLACES
|
17
|
+
MYSQL_REPLACES = [
|
18
|
+
[/ä/, 'a'],
|
19
|
+
[/ö/, 'o'],
|
20
|
+
[/ü/, 'u'],
|
21
|
+
[/Ä/, 'a'],
|
22
|
+
[/Ö/, 'o'],
|
23
|
+
[/Ü/, 'u'],
|
24
|
+
[/ss/, 'ß'],
|
25
|
+
[/SS/, 'ß']
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
30
29
|
# ---------------------------------------------------------------------------------------------------------------------------------
|
31
|
-
#
|
30
|
+
# @!group Clear / Format Text
|
32
31
|
# See TestKyaniteStringChars for tests and examples.
|
33
32
|
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
33
|
+
# Reduces the string to a base94 encoding.
|
34
|
+
# 1. Converts àáâăäãāåạąæảấầắằÀÁÂĂÄÃĀÅẠĄÆẢẤẦẮẰ etc. to aaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAA.
|
35
|
+
# 2. Then removes all non-Ascii-chars.
|
36
|
+
# 3. Then removes all non-printable Ascii-chars.
|
37
|
+
# 4. Caution: Also Newlines are removed.
|
39
38
|
#
|
40
|
-
# See
|
41
|
-
#
|
39
|
+
# See tests and examples {TestKyaniteStringChars#test_reduce94_a here}.
|
40
|
+
# @return [String]
|
42
41
|
def reduce94( options={} )
|
43
42
|
dup.reduce94!(options)
|
44
43
|
end
|
45
44
|
|
46
|
-
|
47
|
-
#
|
45
|
+
|
46
|
+
# In-place-variant of {#reduce94 reduce94}.
|
47
|
+
# @return [String]
|
48
48
|
def reduce94!( options={} )
|
49
49
|
self.gsub!( 'ß', options[:german_sz] ) if options[:german_sz]
|
50
50
|
self.tr!(TR_FULL, TR_REDUCED)
|
@@ -59,12 +59,23 @@ class String
|
|
59
59
|
#
|
60
60
|
# See TestKyaniteStringChars for tests and examples.
|
61
61
|
#
|
62
|
+
|
63
|
+
# Reduces the string to a base53 encoding.
|
64
|
+
# The result consists only uppercase letters, minus, and lowercase characters as replacement for some known special characters.
|
65
|
+
# 1. Removes all non-letter-chars.
|
66
|
+
# 2. Converts all regular letters to upcase letters.
|
67
|
+
# 3. Converts special letters to reduced downcase letters, eg. àáâăäãāåạąæảấầắằÀÁÂĂÄÃĀÅẠĄÆẢẤẦẮẰ etc. to aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.
|
68
|
+
# 4. Caution: Also Newlines are removed.
|
69
|
+
#
|
70
|
+
# See tests and examples {TestKyaniteStringChars#test_reduce53_a here}.
|
71
|
+
# @return [String]
|
62
72
|
def reduce53( options={} )
|
63
73
|
dup.reduce53!(options)
|
64
74
|
end
|
65
75
|
|
66
|
-
|
67
|
-
#
|
76
|
+
|
77
|
+
# In-place-variant of {#reduce53 reduce53}.
|
78
|
+
# @return [String]
|
68
79
|
def reduce53!( options={} )
|
69
80
|
|
70
81
|
if options[:camelcase]
|
@@ -114,43 +125,59 @@ class String
|
|
114
125
|
|
115
126
|
|
116
127
|
# ---------------------------------------------------------------------------------------------------------------------------------
|
117
|
-
#
|
128
|
+
# @!group Upcase and Downcase with support for special letters like german umlauts
|
118
129
|
# See TestKyaniteStringChars for tests and examples.
|
119
130
|
#
|
120
131
|
|
121
|
-
#
|
132
|
+
# Better +downcase+: also works with special letters like german umlauts.
|
133
|
+
# (If you overwrite downcase you will get strange results if you use Active Support.)
|
134
|
+
#
|
135
|
+
# See tests and examples {TestKyaniteStringChars#test_downcase_upcase here}.
|
136
|
+
# @return [String]
|
122
137
|
def downcase2
|
123
138
|
self.tr(TR_UPCASE, TR_DOWNCASE).downcase
|
124
139
|
end
|
125
140
|
|
141
|
+
# In-place-variant of {#downcase2 downcase2}.
|
142
|
+
# @return [String]
|
126
143
|
def downcase2!
|
127
144
|
self.tr!(TR_UPCASE, TR_DOWNCASE).downcase!
|
128
145
|
end
|
129
146
|
|
130
147
|
|
131
|
-
#
|
148
|
+
# Better +upcase+: also works with special letters like german umlauts.
|
149
|
+
# (If you overwrite upcase you will get strange results if you use Active Support.)
|
150
|
+
#
|
151
|
+
# See tests and examples {TestKyaniteStringChars#test_downcase_upcase here}.
|
152
|
+
# @return [String]
|
132
153
|
def upcase2
|
133
154
|
self.tr(TR_DOWNCASE, TR_UPCASE).upcase
|
134
155
|
end
|
135
156
|
|
157
|
+
# In-place-variant of {#upcase2 upcase2}.
|
158
|
+
# @return [String]
|
136
159
|
def upcase2!
|
137
160
|
self.tr!(TR_DOWNCASE, TR_UPCASE).upcase!
|
138
161
|
end
|
139
162
|
|
163
|
+
# Converts the first letter to upcase, also works with special letters like german umlauts.
|
164
|
+
# @return [String]
|
140
165
|
def capitalize
|
141
166
|
(slice(0) || '').upcase2 + (slice(1..-1) || '').downcase2
|
142
167
|
end
|
143
168
|
|
144
169
|
|
145
|
-
#
|
170
|
+
# Is the first letter upcase? Also works with special letters like german umlauts.
|
146
171
|
def capitalized?
|
147
172
|
self =~ TR_UPCASE_ALL_REGEXP
|
148
173
|
end
|
149
174
|
|
175
|
+
# Is the string upcase? Also works with special letters like german umlauts.
|
150
176
|
def upcase?
|
151
177
|
(self == self.upcase)
|
152
178
|
end
|
153
179
|
|
180
|
+
# Is the string downcase? Also works with special letters like german umlauts.
|
154
181
|
def downcase?
|
155
182
|
(self == self.upcase)
|
156
183
|
end
|
@@ -186,8 +213,11 @@ if $0 == __FILE__ then
|
|
186
213
|
#require 'perception'
|
187
214
|
|
188
215
|
#puts "Hallo"
|
189
|
-
puts 'Scheiße'.reduce94(:german_sz => 'z')
|
216
|
+
# puts 'Scheiße'.reduce94(:german_sz => 'z')
|
217
|
+
test_down = 'àáâăäãāåạąæảấầắằабćĉčçċцчďðđдèéêěĕëēėęếеэфĝğġģгĥħхìíîĭïĩīıįijийĵюяķкĺľłļŀлмńňñņŋнòóôŏöõōøőơœопŕřŗрśŝšşсшщţťŧþтùúûŭüũūůűųưувŵýŷÿźżžжз'
|
218
|
+
test_up = 'ÀÁÂĂÄÃĀÅẠĄÆẢẤẦẮẰАБĆĈČÇĊЦЧĎÐĐДÈÉÊĚĔËĒĖĘẾЕЭФĜĞĠĢГĤĦХÌÍÎĬÏĨĪİĮIJИЙĴЮЯĶКĹĽŁĻĿЛМŃŇÑŅŊНÒÓÔŎÖÕŌØŐƠŒОПŔŘŖРŚŜŠŞСШЩŢŤŦÞТÙÚÛŬÜŨŪŮŰŲƯУВŴÝŶŸŹŻŽЖЗ'
|
190
219
|
|
220
|
+
puts "hallo".upcase!
|
191
221
|
|
192
222
|
|
193
223
|
end
|
@@ -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 'hashery'
|
9
10
|
require 'kyanite/string/div'
|
10
11
|
|
data/lib/kyanite/string/diff.rb
CHANGED
@@ -1,16 +1,23 @@
|
|
1
|
-
# ruby encoding: utf-8
|
1
|
+
# ruby encoding: utf-8
|
2
2
|
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
3
7
|
|
4
|
-
class String
|
5
8
|
|
9
|
+
|
10
|
+
class String
|
11
|
+
|
12
|
+
# @!group Overlap / Diff
|
13
|
+
|
6
14
|
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
# Gibt den gemeinsamen Teil zweier Strings aus (von vorne gezählt).
|
15
|
+
# Returns the mutual part of two strings. Example:
|
16
|
+
# "Hello world".overlap("Hello darling")
|
17
|
+
# => "Hello"
|
12
18
|
#
|
13
|
-
#
|
19
|
+
# See more examples and tests {TestKyaniteStringDiff#test_overlap here}.
|
20
|
+
# @return [String] mutual part
|
14
21
|
def overlap(b)
|
15
22
|
return '' if b.nil?
|
16
23
|
b = b.to_str
|
@@ -22,18 +29,22 @@ class String
|
|
22
29
|
end
|
23
30
|
|
24
31
|
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
32
|
+
# Returns the differencing part of two strings. Example:
|
33
|
+
# "Hello darling".diff("Hello")
|
34
|
+
# => " darling"
|
35
|
+
#
|
36
|
+
# When in doubt, the longest differencing string.
|
37
|
+
# If there is still doubt, then +self+.
|
38
|
+
#
|
39
|
+
# See more examples and tests {TestKyaniteStringDiff#test_diff here}.
|
40
|
+
# @return [String] differencing part
|
30
41
|
def diff(b)
|
31
42
|
return self if b.nil?
|
32
43
|
b = b.to_str
|
33
44
|
return '' if self == b # kein Unterschied
|
34
45
|
|
35
46
|
a = self
|
36
|
-
a,b = b,a if a.size >= b.size # a ist jetzt k
|
47
|
+
a,b = b,a if a.size >= b.size # a ist jetzt k?rzer oder gleichlang wie b
|
37
48
|
overlap = a.overlap(b)
|
38
49
|
return self if overlap == ''
|
39
50
|
return b.split(overlap)[1]
|
@@ -41,19 +52,24 @@ class String
|
|
41
52
|
|
42
53
|
|
43
54
|
|
44
|
-
|
45
|
-
# Symmetrie: Rechnet man overlap + diff, so erhält man immer den längsten der beiden ursprünglichen Strings.
|
46
|
-
# Waren beide gleichlang, so erhält man self.
|
55
|
+
|
47
56
|
# overlapdiff braucht genauso viel Zeit wie diff alleine.
|
57
|
+
|
58
|
+
# Returns {#diff diff} and {#overlap overlap} in one array.
|
59
|
+
# Takes as much time as +diff+ alone.
|
60
|
+
#
|
61
|
+
# Symmetry: If we add +overlap+ + +diff+, we always get the longest of the two original strings.
|
62
|
+
# If both had the same length, we get +self+.
|
48
63
|
#
|
49
|
-
#
|
64
|
+
# See examples and tests {TestKyaniteStringDiff#test_overlapdiff here}.
|
65
|
+
# @return [Array] mutual part, differencing part
|
50
66
|
def overlapdiff(b)
|
51
67
|
return '', self if b.nil?
|
52
68
|
b = b.to_str
|
53
69
|
return self,'' if self == b # kein Unterschied
|
54
70
|
|
55
71
|
a = self
|
56
|
-
a,b = b,a if a.size >= b.size # a ist jetzt k
|
72
|
+
a,b = b,a if a.size >= b.size # a ist jetzt k?rzer oder gleichlang wie b
|
57
73
|
overlap = a.overlap(b)
|
58
74
|
return overlap, self if overlap == ''
|
59
75
|
return overlap, b.split(overlap)[1]
|
@@ -64,24 +80,38 @@ class String
|
|
64
80
|
end
|
65
81
|
|
66
82
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
83
|
+
|
84
|
+
class NilClass
|
85
|
+
|
86
|
+
# see {String#overlap}
|
87
|
+
# @return [String] Empty String
|
88
|
+
def overlap(*a); ''; end
|
89
|
+
|
90
|
+
|
91
|
+
# see {String#diff}
|
92
|
+
# @return [String] Parameter b
|
93
|
+
def diff(b); b; end
|
94
|
+
|
95
|
+
|
96
|
+
# see {String#overlapdiff}
|
97
|
+
# @return [Array] ['', b]
|
98
|
+
def overlapdiff(b); ['', b]; end
|
82
99
|
end
|
83
100
|
|
84
101
|
|
102
|
+
# -----------------------------------------------------------------------------------------
|
103
|
+
# Ausprobieren
|
104
|
+
#
|
105
|
+
if $0 == __FILE__ then
|
106
|
+
|
107
|
+
puts "Hello darling".diff("Hello")
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
end
|
85
115
|
|
86
116
|
|
87
117
|
|