hash-utils 0.17.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -2,7 +2,7 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  git (1.2.5)
5
- jeweler (1.6.2)
5
+ jeweler (1.6.3)
6
6
  bundler (~> 1.0)
7
7
  git (>= 1.2.5)
8
8
  rake
data/README.md CHANGED
@@ -15,9 +15,10 @@ non-atomic and organized by better way.
15
15
  - `IO` – 1 method,
16
16
  - `Module` – 1 method,
17
17
  - `Numeric` – 5 method,
18
- - `Object` – 12 methods,
18
+ - `Object` – 13 methods,
19
+ - `Proc` – 1 method,
19
20
  - `TrueClass` – 3 methods,
20
- - `String` – 35 methods,
21
+ - `String` – 37 methods,
21
22
  - `StringIO` – 1 method,
22
23
  - `Symbol` – 8 methods.
23
24
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.17.1
1
+ 0.18.0
data/hash-utils.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hash-utils}
8
- s.version = "0.17.1"
8
+ s.version = "0.18.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Martin Kozák}]
12
- s.date = %q{2011-06-24}
12
+ s.date = %q{2011-07-14}
13
13
  s.email = %q{martinkozak@martinkozak.net}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/hash-utils/module.rb",
36
36
  "lib/hash-utils/numeric.rb",
37
37
  "lib/hash-utils/object.rb",
38
+ "lib/hash-utils/proc.rb",
38
39
  "lib/hash-utils/string.rb",
39
40
  "lib/hash-utils/stringio.rb",
40
41
  "lib/hash-utils/symbol.rb",
data/lib/hash-utils.rb CHANGED
@@ -4,11 +4,13 @@
4
4
  require "hash-utils/array"
5
5
  require "hash-utils/boolean"
6
6
  require "hash-utils/file"
7
+ require "hash-utils/gem"
7
8
  require "hash-utils/hash"
8
9
  require "hash-utils/io"
9
10
  require "hash-utils/module"
10
11
  require "hash-utils/numeric"
11
12
  require "hash-utils/object"
13
+ require "hash-utils/proc"
12
14
  require "hash-utils/string"
13
15
  require "hash-utils/stringio"
14
16
  require "hash-utils/symbol"
@@ -9,6 +9,8 @@ require "hash-utils/gem"
9
9
 
10
10
  class Array
11
11
 
12
+ @__sum_check_done
13
+
12
14
  ##
13
15
  # Moves selected values outside the array, so returns them.
14
16
  #
@@ -188,9 +190,12 @@ class Array
188
190
  #
189
191
 
190
192
  def sum
191
- if RUBY_VERSION[0..2] == "1.9" \
192
- or (Gem::require_available("ruby-version") and Ruby::Version >= [1, 8, 7])
193
+ if @__sum_check_done \
194
+ or RUBY_VERSION[0..2] == "1.9" \
195
+ or RUBY_VERSION[0..4] == "1.8.7" \
196
+ or (Gem::require_available("ruby-version") and Ruby::Version > [1, 8, 7])
193
197
 
198
+ @__sum_check_done = true
194
199
  self.inject(:+)
195
200
  else
196
201
  first = true
@@ -148,6 +148,17 @@ class Object
148
148
  self.kind_of? Symbol
149
149
  end
150
150
 
151
+ ##
152
+ # Indicates, object is +Proc+.
153
+ #
154
+ # @return [Boolean] +true+ if yes, +false+ in otherwise
155
+ # @since 0.18.0
156
+ #
157
+
158
+ def proc?
159
+ self.kind_of? Proc
160
+ end
161
+
151
162
  ##
152
163
  # Indicates, object is +Numeric+.
153
164
  #
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
4
+ ##
5
+ # Proc extension.
6
+ # @since 0.18.0
7
+ #
8
+
9
+ class Proc
10
+
11
+ ##
12
+ # Indicates, object is kind of Proc.
13
+ #
14
+ # @return [Boolean] +true+ if yes, +false+ in otherwise
15
+ # @since 0.18.0
16
+ #
17
+
18
+ def proc?
19
+ true
20
+ end
21
+
22
+ end
@@ -582,6 +582,35 @@ class String
582
582
  true
583
583
  end
584
584
 
585
+ ##
586
+ # Swaps two strings. Return new content of self.
587
+ #
588
+ # @param [String] from source string
589
+ # @return [String] new content of self
590
+ # @since 0.18.0
591
+ #
592
+
593
+ def swap_with(from)
594
+ intermediate = self.dup
595
+ self.replace(from)
596
+ from.replace(intermediate)
597
+ return self
598
+ end
599
+
600
+ alias :"swap_with!" :swap_with
601
+
602
+ ##
603
+ # Cuts string on place. Sets the content of #[] on place of
604
+ # the string.
605
+ #
606
+ # @param [Range] range range with from and to limits
607
+ # @return [String] itself
608
+ # @since 0.18.0
609
+ #
610
+
611
+ def cut!(range)
612
+ self.replace(self[range])
613
+ end
585
614
 
586
615
 
587
616
  private
data/test CHANGED
@@ -265,6 +265,10 @@ context "Object" do
265
265
  asserts("#number?") do
266
266
  not :abcd.number? and 5.number?
267
267
  end
268
+ asserts("#proc?") do
269
+ proc = Proc::new { }
270
+ not :abcd.proc? and proc.proc?
271
+ end
268
272
  asserts("#string?") do
269
273
  "".string? and not 5.string?
270
274
  end
@@ -306,6 +310,11 @@ context "String" do
306
310
  asserts("#eighth") do
307
311
  "abcdefgh".eighth == ?h
308
312
  end
313
+ asserts("#cut!") do
314
+ foo = "0123456789"
315
+ foo.cut! 3..5
316
+ foo == "345"
317
+ end
309
318
  asserts("#first_line") do
310
319
  res = true
311
320
  res &= "a\nb\nc\n".first_line == "a\n"
@@ -395,6 +404,12 @@ context "String" do
395
404
  asserts("#string?") do
396
405
  "abcd".string?
397
406
  end
407
+ asserts("#swap_with") do
408
+ foo = "abc"
409
+ bar = "123"
410
+ foo.swap_with(bar)
411
+ foo = "123" and bar = "abc"
412
+ end
398
413
  asserts("#ucfirst") do
399
414
  str = "abcd"
400
415
  str.ucfirst == "Abcd" and str == "abcd"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hash-utils
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.17.1
5
+ version: 0.18.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Martin Koz\xC3\xA1k"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-24 00:00:00 Z
13
+ date: 2011-07-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -74,6 +74,7 @@ files:
74
74
  - lib/hash-utils/module.rb
75
75
  - lib/hash-utils/numeric.rb
76
76
  - lib/hash-utils/object.rb
77
+ - lib/hash-utils/proc.rb
77
78
  - lib/hash-utils/string.rb
78
79
  - lib/hash-utils/stringio.rb
79
80
  - lib/hash-utils/symbol.rb
@@ -92,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
93
  requirements:
93
94
  - - ">="
94
95
  - !ruby/object:Gem::Version
95
- hash: 654808796708422656
96
+ hash: -1491975354394754334
96
97
  segments:
97
98
  - 0
98
99
  version: "0"