ruby-nuggets 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Rakefile +2 -1
- data/lib/nuggets/array/runiq.rb +5 -0
- data/lib/nuggets/array/runiq_mixin.rb +53 -0
- data/lib/nuggets/string/xor.rb +5 -0
- data/lib/nuggets/string/xor_mixin.rb +60 -0
- data/lib/nuggets/version.rb +1 -1
- metadata +8 -4
data/README
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
+
# language. #
|
6
|
+
# #
|
7
|
+
# Copyright (C) 2007-2009 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
+
# #
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
+
# any later version. #
|
16
|
+
# #
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
+
# more details. #
|
21
|
+
# #
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
+
# #
|
25
|
+
###############################################################################
|
26
|
+
#++
|
27
|
+
|
28
|
+
module Nuggets
|
29
|
+
class Array
|
30
|
+
module RuniqMixin
|
31
|
+
|
32
|
+
# call-seq:
|
33
|
+
# array.runiq => an_array
|
34
|
+
#
|
35
|
+
# Reverse #uniq.
|
36
|
+
def runiq
|
37
|
+
reverse.uniq.reverse
|
38
|
+
end
|
39
|
+
|
40
|
+
# call-seq:
|
41
|
+
# array.runiq! => an_array or nil
|
42
|
+
#
|
43
|
+
# Reverse #uniq!.
|
44
|
+
def runiq!
|
45
|
+
reverse!
|
46
|
+
res = uniq!
|
47
|
+
reverse!
|
48
|
+
res && self
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
+
# language. #
|
6
|
+
# #
|
7
|
+
# Copyright (C) 2007-2009 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
+
# #
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
+
# any later version. #
|
16
|
+
# #
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
+
# more details. #
|
21
|
+
# #
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
+
# #
|
25
|
+
###############################################################################
|
26
|
+
#++
|
27
|
+
|
28
|
+
require 'nuggets/integer/to_binary_s'
|
29
|
+
|
30
|
+
module Nuggets
|
31
|
+
class String
|
32
|
+
module XorMixin
|
33
|
+
|
34
|
+
# call-seq:
|
35
|
+
# str ^ other => new_string
|
36
|
+
# str.xor(other) => new_string
|
37
|
+
#
|
38
|
+
# Bitwise EXCLUSIVE OR.
|
39
|
+
def xor(other, require_same_length = false)
|
40
|
+
format = 'B*'
|
41
|
+
binary = [self, other.to_s].map { |s| s.unpack(format).first }
|
42
|
+
|
43
|
+
length = binary.map { |s| s.length }.inject { |a, b|
|
44
|
+
if require_same_length
|
45
|
+
a == b ? a : raise(ArgumentError, 'must be of same length')
|
46
|
+
else
|
47
|
+
[a, b].max
|
48
|
+
end
|
49
|
+
}
|
50
|
+
|
51
|
+
[binary.map { |s| s.to_i(2) }.
|
52
|
+
inject { |a, b| a ^ b }.
|
53
|
+
to_binary_s(length)].pack(format)
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_method :^, :xor
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/nuggets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nuggets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-29 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/nuggets/numeric/signum.rb
|
38
38
|
- lib/nuggets/array/to_hash.rb
|
39
39
|
- lib/nuggets/array/variance.rb
|
40
|
+
- lib/nuggets/array/runiq_mixin.rb
|
40
41
|
- lib/nuggets/array/shuffle.rb
|
41
42
|
- lib/nuggets/array/variance_mixin.rb
|
42
43
|
- lib/nuggets/array/standard_deviation_mixin.rb
|
@@ -45,6 +46,7 @@ files:
|
|
45
46
|
- lib/nuggets/array/monotone.rb
|
46
47
|
- lib/nuggets/array/only.rb
|
47
48
|
- lib/nuggets/array/flatten_once.rb
|
49
|
+
- lib/nuggets/array/runiq.rb
|
48
50
|
- lib/nuggets/array/standard_deviation.rb
|
49
51
|
- lib/nuggets/array/rand.rb
|
50
52
|
- lib/nuggets/array/combination.rb
|
@@ -77,6 +79,8 @@ files:
|
|
77
79
|
- lib/nuggets/string/wc.rb
|
78
80
|
- lib/nuggets/string/sub_with_md.rb
|
79
81
|
- lib/nuggets/string/nsub.rb
|
82
|
+
- lib/nuggets/string/xor_mixin.rb
|
83
|
+
- lib/nuggets/string/xor.rb
|
80
84
|
- lib/nuggets/string/word_wrap.rb
|
81
85
|
- lib/nuggets/integer/length.rb
|
82
86
|
- lib/nuggets/integer/to_binary_s.rb
|
@@ -122,12 +126,12 @@ licenses: []
|
|
122
126
|
|
123
127
|
post_install_message:
|
124
128
|
rdoc_options:
|
129
|
+
- --title
|
130
|
+
- ruby-nuggets Application documentation
|
125
131
|
- --main
|
126
132
|
- README
|
127
133
|
- --line-numbers
|
128
134
|
- --inline-source
|
129
|
-
- --title
|
130
|
-
- ruby-nuggets Application documentation
|
131
135
|
- --all
|
132
136
|
- --charset
|
133
137
|
- UTF-8
|