kyanite 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,33 +1,29 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
WINDOWS = /djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM ? RUBY_PLATFORM : false
|
7
|
-
end
|
8
|
-
|
9
|
-
unless defined? RUBYDIR
|
10
|
-
RUBYDIR = RbConfig::CONFIG['prefix']
|
11
|
-
# puts "rubydir=" + RUBYDIR
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
12
6
|
end
|
13
7
|
|
8
|
+
require 'facets/timer'
|
14
9
|
|
15
10
|
|
16
11
|
|
17
|
-
#
|
18
|
-
# [ ] | Object | *KKernel* | CallerUtils | Undoable | Class |
|
19
|
-
#
|
20
|
-
# ---
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# == *General* *Tools*
|
24
|
-
#
|
25
|
-
#
|
12
|
+
# @!macro object
|
26
13
|
module KKernel
|
27
14
|
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
15
|
+
# @!macro [new] seconds
|
16
|
+
# Repeats a block until the time is up.
|
17
|
+
# Returns the number of passes. All Exceptions are caught (=> bad blocks seem to run faster).
|
18
|
+
# Example (using {Numeric}):
|
19
|
+
# 3.seconds do
|
20
|
+
# puts Time.now.inspect
|
21
|
+
# end
|
22
|
+
# Example (using {KKernel}):
|
23
|
+
# repeat_n_seconds 3 do
|
24
|
+
# puts Time.now.inspect
|
25
|
+
# end
|
26
|
+
#
|
31
27
|
def repeat_n_seconds( n=1, &block )
|
32
28
|
timer = Timer.new(n)
|
33
29
|
begin
|
@@ -35,7 +31,7 @@ module KKernel
|
|
35
31
|
count = 0
|
36
32
|
until false
|
37
33
|
count += 1
|
38
|
-
yield block
|
34
|
+
yield block if block
|
39
35
|
end
|
40
36
|
timer.stop
|
41
37
|
rescue TimeoutError
|
@@ -50,9 +46,15 @@ module KKernel
|
|
50
46
|
|
51
47
|
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
#
|
49
|
+
|
50
|
+
|
51
|
+
# Silence all Ruby warnings for the following block. Useful to override constants.
|
52
|
+
# Example:
|
53
|
+
# TEST = 1
|
54
|
+
# silence_warnings do
|
55
|
+
# TEST = 2
|
56
|
+
# end
|
57
|
+
#
|
56
58
|
def silence_warnings
|
57
59
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
58
60
|
yield
|
@@ -61,58 +63,37 @@ module KKernel
|
|
61
63
|
end
|
62
64
|
|
63
65
|
|
64
|
-
|
65
|
-
# Beim lokalen Aufruf eines einzelnen Tests wird die lokale Version der Library verwendet, nicht die installierte gem.
|
66
|
-
# Verwendung:
|
67
|
-
# if $0 == __FILE__
|
68
|
-
# require 'kyanite/smart_load_path'
|
69
|
-
# smart_load_path
|
70
|
-
# end
|
71
|
-
# require 'mygemproject'
|
72
|
-
#
|
73
|
-
def smart_load_path(__file__ = nil)
|
74
|
-
__file__ = caller[0] unless __file__
|
75
|
-
dir_caller =File.dirname(__file__)
|
76
|
-
|
77
|
-
#puts "smart_load_path " + dir_caller
|
78
|
-
|
79
|
-
patharray = dir_caller.split('/')
|
80
|
-
patharray = dir_caller.split("\\") if patharray.size == 1
|
81
|
-
# libpath = File.join(patharray)
|
82
|
-
patharray.size.times do |i|
|
83
|
-
break if File.directory?( File.join(patharray, 'lib') )
|
84
|
-
patharray << '..'
|
85
|
-
end
|
86
|
-
newpath = File.join(patharray,'lib')
|
87
|
-
if $:.include?(newpath)
|
88
|
-
return false
|
89
|
-
else
|
90
|
-
$:.unshift(newpath)
|
91
|
-
return true
|
92
|
-
end
|
93
|
-
|
94
|
-
end #def
|
66
|
+
|
95
67
|
|
96
68
|
|
97
|
-
end
|
69
|
+
end
|
98
70
|
|
99
71
|
class Object
|
100
72
|
include KKernel
|
101
73
|
end
|
102
74
|
|
75
|
+
class Numeric
|
76
|
+
|
77
|
+
# @!macro seconds
|
78
|
+
def seconds( &block )
|
79
|
+
repeat_n_seconds( self ) do
|
80
|
+
yield block if block
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
103
86
|
|
104
87
|
# ---------------------------------------------------------
|
105
88
|
# Ausprobieren
|
106
89
|
#
|
107
90
|
if $0 == __FILE__
|
108
91
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
$LOAD_PATH.each do |path|
|
113
|
-
puts path
|
92
|
+
TEST = 1
|
93
|
+
silence_warnings do
|
94
|
+
TEST = 2
|
114
95
|
end
|
115
|
-
|
96
|
+
puts TEST
|
116
97
|
end
|
117
98
|
|
118
99
|
|
@@ -1,46 +1,39 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
2
8
|
|
3
9
|
|
4
|
-
#
|
5
|
-
# [ ] | *Object* | KKernel | CallerUtils | Undoable | Class |
|
6
|
-
#
|
7
|
-
# ---
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# == *For* *All* *Objects*
|
11
|
-
# Tests and examples see TestKyaniteObject
|
12
|
-
#
|
13
|
-
#
|
10
|
+
# @!macro object
|
14
11
|
class Object
|
15
12
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# Tests and examples see TestKyaniteObject
|
19
|
-
#
|
13
|
+
# Returns +false+
|
14
|
+
# @return [false]
|
20
15
|
def blank?
|
21
16
|
false
|
22
17
|
end
|
23
18
|
|
24
19
|
|
25
|
-
|
26
|
-
#
|
20
|
+
|
21
|
+
# Like +respond_to?+ but returns the result of the call if it does indeed respond.
|
22
|
+
# See {http://rubyworks.github.com/rubyfaux/?doc=http://rubyworks.github.com/facets/docs/facets-2.9.3/core.json#api-module-Kernel/api-method-Kernel-h-respond Facets +Kernel#respond+}.
|
27
23
|
def respond(sym, *args)
|
28
24
|
return nil if not respond_to?(sym)
|
29
25
|
send(sym, *args)
|
30
26
|
end
|
31
27
|
|
32
28
|
|
33
|
-
#
|
34
|
-
# Wird z.B. für Undo-Operationen verwendet, siehe Modul Undoable.
|
35
|
-
#
|
29
|
+
# Slow but in-depth alternative to +dup+. Also duplicates sub-objects. Is e.g. for undo operations used, see module {Undoable}.
|
36
30
|
def deep_copy
|
37
31
|
Marshal.load( Marshal.dump( self ) )
|
38
32
|
end
|
39
33
|
|
40
34
|
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# Tests and examples see TestKyaniteObject
|
35
|
+
# Is the object numeric?
|
36
|
+
# Tests see {TestKyaniteObject here}.
|
44
37
|
#
|
45
38
|
def is_numeric?
|
46
39
|
Float self
|
@@ -48,30 +41,13 @@ class Object
|
|
48
41
|
false
|
49
42
|
end
|
50
43
|
|
51
|
-
|
52
|
-
#
|
44
|
+
# Returns +false+
|
45
|
+
# @return [false]
|
53
46
|
def empty?
|
54
47
|
false
|
55
48
|
end
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# Liefert nil, wenn die Condition erfüllt ist. Sonst self.
|
62
|
-
#
|
63
|
-
def to_nil(condition = :empty)
|
64
|
-
return nil if self.respond(condition.to_s + '?')
|
65
|
-
return self
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
# Liefert nil, wenn die Condition nicht erfüllt ist. Sonst self.
|
70
|
-
#
|
71
|
-
def to_nil_unless(condition = :empty)
|
72
|
-
return nil unless self.respond(condition.to_s + '?')
|
73
|
-
return self
|
74
|
-
end
|
50
|
+
|
75
51
|
|
76
52
|
|
77
53
|
# Findet den Namen einer Ruby-Konstanten anhand seines Wertes.
|
@@ -88,14 +64,14 @@ end
|
|
88
64
|
if defined? TransparentNil
|
89
65
|
class NilClass
|
90
66
|
|
91
|
-
#
|
67
|
+
# +false+
|
68
|
+
# @return [false]
|
92
69
|
def blank?; false; end
|
93
70
|
|
94
|
-
#
|
71
|
+
# +false+
|
72
|
+
# @return [false]
|
95
73
|
def is_numeric?; false; end
|
96
74
|
|
97
|
-
def to_nil; nil; end
|
98
|
-
def to_nil_unless(*a); nil; end
|
99
75
|
def name_of_constant(*a); nil; end
|
100
76
|
end
|
101
77
|
end
|
@@ -1,34 +1,40 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
# @!macro true_false
|
9
10
|
class TrueClass
|
10
11
|
|
11
12
|
|
12
|
-
#
|
13
|
+
# Returns +1+
|
14
|
+
# @return [1]
|
13
15
|
def to_i; 1; end
|
14
16
|
|
15
17
|
|
16
|
-
#
|
18
|
+
# Returns +self+
|
19
|
+
# @return [self]
|
17
20
|
def strip; self; end
|
18
21
|
|
19
22
|
|
20
|
-
#
|
23
|
+
# Returns +self+
|
24
|
+
# @return [self]
|
21
25
|
def dup; self; end
|
26
|
+
|
22
27
|
|
23
|
-
|
24
|
-
#
|
28
|
+
# Defines true <=> true, true <=> false, false <=> true, false <=> false.
|
29
|
+
# See Tests {TestKyaniteTrueFalse#test_raumschiff_operator here}.
|
25
30
|
def <=>(other)
|
26
31
|
return 1 if ! other
|
27
32
|
return 0
|
28
33
|
end
|
29
34
|
|
30
35
|
|
31
|
-
#
|
36
|
+
# Returns +false+
|
37
|
+
# @return [false]
|
32
38
|
def blank?; false; end
|
33
39
|
|
34
40
|
|
@@ -37,33 +43,33 @@ end # class
|
|
37
43
|
|
38
44
|
|
39
45
|
|
40
|
-
#
|
41
|
-
#
|
42
|
-
# ---
|
43
|
-
#
|
44
|
-
# == *False*
|
45
|
-
#
|
46
|
+
# @!macro true_false
|
46
47
|
class FalseClass
|
47
48
|
|
48
|
-
#
|
49
|
+
# Returns +0+
|
50
|
+
# @return [0]
|
49
51
|
def to_i; 0; end
|
50
|
-
|
51
|
-
|
52
|
+
|
53
|
+
|
54
|
+
# Returns +self+
|
55
|
+
# @return [self]
|
52
56
|
def strip; self; end
|
57
|
+
|
53
58
|
|
54
|
-
#
|
59
|
+
# Returns +self+
|
60
|
+
# @return [self]
|
55
61
|
def dup; self; end
|
62
|
+
|
56
63
|
|
57
|
-
# see
|
64
|
+
# (see TrueClass#<=>)
|
58
65
|
def <=>(other)
|
59
66
|
return -1 if other
|
60
67
|
return 0
|
61
68
|
end
|
62
69
|
|
63
70
|
|
64
|
-
#
|
65
|
-
#
|
66
|
-
# TestKyaniteObject#test_blank
|
71
|
+
# Returns +false+
|
72
|
+
# @return [self]
|
67
73
|
def blank?; self; end
|
68
74
|
|
69
75
|
|
@@ -1,20 +1,18 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
2
7
|
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# ---
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# == *Undo*
|
10
|
-
#
|
11
|
-
#
|
8
|
+
|
9
|
+
# @!macro undoable
|
12
10
|
module Undoable
|
13
11
|
|
14
12
|
@@undoable_history = Hash.new
|
15
13
|
|
16
|
-
#
|
17
|
-
#
|
14
|
+
# Saves an object.
|
15
|
+
# @param method [Symbol] method to use. Default is +:dup+. For more complex objects use {Object#deep_copy +:deep_copy+} instead.
|
18
16
|
#
|
19
17
|
def save(method=:dup)
|
20
18
|
return if self == @@undoable_history[self.object_id] # nichts zu tun
|
@@ -22,23 +20,21 @@ module Undoable
|
|
22
20
|
end
|
23
21
|
|
24
22
|
|
25
|
-
#
|
26
|
-
# Der gespeicherte Zustand verbleibt im Speicher.
|
23
|
+
# Loads a saved state of an object, the saved state remains in memory.
|
27
24
|
#
|
28
25
|
def load_and_keep
|
29
26
|
@@undoable_history[self.object_id]
|
30
27
|
end
|
31
28
|
|
32
29
|
|
33
|
-
#
|
34
|
-
# Der gespeicherte Zustand wird verworfen.
|
30
|
+
# Loads a saved state of an object, the saved state will be discarded.
|
35
31
|
#
|
36
32
|
def load_and_delete
|
37
33
|
@@undoable_history.delete(self.object_id)
|
38
34
|
end
|
39
35
|
|
40
36
|
|
41
|
-
#
|
37
|
+
# Discards all saved states of all objects.
|
42
38
|
#
|
43
39
|
def self.clear
|
44
40
|
@@undoable_history.clear
|
data/lib/kyanite/hash.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
2
8
|
require 'active_support/core_ext/hash/slice' # Slice a hash to include only the given keys.
|
3
9
|
require 'active_support/core_ext/hash/reverse_merge' # Merges the caller into +other_hash+.
|
4
10
|
require 'kyanite/enumerable' # is_collection?
|
@@ -11,72 +17,56 @@ require 'kyanite/enumerable' # is_collection?
|
|
11
17
|
|
12
18
|
|
13
19
|
|
14
|
-
# [ | Kyanite | Object | Array | Set | Enumerable | *Hash* | ] | *Hash* | Dictionary |
|
15
|
-
# ---
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# == *Tools* *For* *Hash*
|
19
|
-
# See TestKyaniteHash for tests and examples.
|
20
|
-
#
|
21
|
-
# === Generelle Anmerkungen zu Hashes
|
22
|
-
# Definiert man in irgendeinem Objekt die Methode <tt>==(other)</tt>, so muss man auch die Methode +hash+ neu definieren!
|
23
|
-
#
|
24
|
-
# Rubys +delete+ und +delete_if+ verändern den Hash! Siehe TestHash#test_delete
|
25
|
-
#
|
26
|
-
#
|
27
|
-
class Hash
|
28
20
|
|
29
21
|
|
30
|
-
|
31
|
-
|
32
|
-
# Credit: Paul Murur http://mucur.name/posts/when-is-a-set-not-a-set
|
33
|
-
# Create a hash based on the keys and values.
|
34
|
-
def hash
|
35
|
-
keys.hash + values.hash + (default ? default.hash : 0)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Credit: Paul Murur http://mucur.name/posts/when-is-a-set-not-a-set
|
39
|
-
# To determine whether two hashes are the same, compare their hashes.
|
40
|
-
def eql?(other)
|
41
|
-
hash == other.hash
|
42
|
-
end
|
43
|
-
|
44
|
-
end # Ruby Version
|
22
|
+
# @!macro hash
|
23
|
+
class Hash
|
45
24
|
|
46
25
|
|
47
|
-
|
48
|
-
#
|
49
|
-
# Tests: TestHash#test_delete
|
26
|
+
# Deletes all key-value pairs with <b>nil-keys</b> in-place.
|
27
|
+
# @return [Hash] in-place modificated
|
50
28
|
def compact_keys!
|
51
29
|
delete_if {|key, value| key.nil? }
|
52
30
|
end
|
53
31
|
|
54
32
|
|
55
|
-
#
|
56
|
-
#
|
33
|
+
# Deletes all key-value pairs with <b>nil-values</b> in-place.
|
34
|
+
# @return [Hash] in-place modificated
|
57
35
|
def compact_values!
|
58
36
|
delete_if {|key, value| value.nil? }
|
59
37
|
end
|
60
38
|
|
61
39
|
|
62
|
-
#
|
63
|
-
#
|
40
|
+
# Deletes the key-value pair with a <b>given key</b> in-place.
|
41
|
+
# Returns the modificated hash (in contrast to Rubys +delete+ method that returns the deleted key-value pair! ).
|
42
|
+
# @return [Hash] in-place modificated
|
64
43
|
def delete_key(key)
|
65
44
|
delete_if { |k,v| k == key }
|
66
45
|
end
|
67
46
|
|
68
|
-
#
|
69
|
-
#
|
47
|
+
# Deletes all key-value pairs with a <b>given value</b> in-place.
|
48
|
+
# Returns the modificated hash (in contrast to Rubys +delete+ method that returns the deleted key-value pair! ).
|
49
|
+
# @return [Hash] in-place modificated
|
70
50
|
def delete_value(value)
|
71
51
|
delete_if { |k,v| v == value }
|
72
52
|
end
|
73
53
|
|
74
|
-
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
54
|
+
|
55
|
+
# Forces some options in a methods options hash to be an array.
|
56
|
+
# Useful if both individual values and arrays are allowed as an input option.
|
57
|
+
#
|
58
|
+
# Example:
|
59
|
+
# options = { :skip => 1, :debug => true, :test => false }
|
60
|
+
# puts options
|
61
|
+
# => {:skip=>1, :debug=>true, :test=>false}
|
62
|
+
#
|
63
|
+
# options.arrayize!(:skip, :debug)
|
64
|
+
# puts options
|
65
|
+
# => {:skip=>[1], :debug=>[true], :test=>false}
|
78
66
|
#
|
79
|
-
|
67
|
+
# @return [Hash]
|
68
|
+
# @param keys [Key, Array of keys] Keys to process
|
69
|
+
def arrayize!(*keys)
|
80
70
|
keys.each do |k|
|
81
71
|
if self[k] && !self[k].respond_to?(:first)
|
82
72
|
self[k] = [self[k]]
|
@@ -87,7 +77,7 @@ class Hash
|
|
87
77
|
end
|
88
78
|
|
89
79
|
|
90
|
-
#
|
80
|
+
# Accesses the hash with keys that do not match exactly
|
91
81
|
#
|
92
82
|
def fuzzyget(key, level = 3)
|
93
83
|
try = self[key]
|
@@ -99,12 +89,9 @@ class Hash
|
|
99
89
|
end
|
100
90
|
|
101
91
|
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
# Siehe auch Enumerable#distribution.
|
106
|
-
# Die Keys des Hash werden ignoriert.
|
107
|
-
#
|
92
|
+
# Returns the distribution of +size+, +class+ or any other characteristic of the enumerated elements.
|
93
|
+
# The keys of the hash will be ignored. See also {Enumerable#distribution}, examples there.
|
94
|
+
# @return [Array]
|
108
95
|
def distribution( mode = :size)
|
109
96
|
verteilung = Hash.new
|
110
97
|
each do | key, element |
|
@@ -119,8 +106,8 @@ class Hash
|
|
119
106
|
end
|
120
107
|
|
121
108
|
|
122
|
-
|
123
|
-
#
|
109
|
+
|
110
|
+
# @return any value
|
124
111
|
def first
|
125
112
|
self.each do |key, value|
|
126
113
|
return value
|
@@ -128,8 +115,7 @@ class Hash
|
|
128
115
|
end #def
|
129
116
|
|
130
117
|
|
131
|
-
#
|
132
|
-
#
|
118
|
+
# @return any other value
|
133
119
|
def last
|
134
120
|
first = nil
|
135
121
|
self.each do |key, value|
|
@@ -143,7 +129,21 @@ class Hash
|
|
143
129
|
end #def
|
144
130
|
|
145
131
|
|
146
|
-
|
132
|
+
# if RUBY_VERSION < "1.9"
|
133
|
+
|
134
|
+
# Credit: Paul Murur http://mucur.name/posts/when-is-a-set-not-a-set
|
135
|
+
# Create a hash based on the keys and values.
|
136
|
+
# def hash
|
137
|
+
# keys.hash + values.hash + (default ? default.hash : 0)
|
138
|
+
# end
|
139
|
+
|
140
|
+
# Credit: Paul Murur http://mucur.name/posts/when-is-a-set-not-a-set
|
141
|
+
# To determine whether two hashes are the same, compare their hashes.
|
142
|
+
# def eql?(other)
|
143
|
+
# hash == other.hash
|
144
|
+
# end
|
145
|
+
|
146
|
+
# end # Ruby Version
|
147
147
|
|
148
148
|
|
149
149
|
end #class
|
@@ -167,9 +167,14 @@ end
|
|
167
167
|
#
|
168
168
|
if $0 == __FILE__
|
169
169
|
|
170
|
-
|
171
|
-
|
172
|
-
|
170
|
+
require 'perception'
|
171
|
+
|
172
|
+
options = { :skip => 1, :debug => true, :test => false }
|
173
|
+
puts options
|
174
|
+
options.arrayize!(:skip)
|
175
|
+
puts options
|
176
|
+
|
177
|
+
|
173
178
|
|
174
179
|
|
175
180
|
|