ruby-nuggets 0.1.1.214 → 0.1.2.215

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.1.1
5
+ This documentation refers to ruby-nuggets version 0.1.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -30,9 +30,9 @@ require File.join(File.dirname(__FILE__), 'flatten_once')
30
30
  class Array
31
31
 
32
32
  # call-seq:
33
- # array.to_h => aHash
34
- # array.to_h(value) => aHash
35
- # array.to_h { |element| ... } => aHash
33
+ # array.to_hash => aHash
34
+ # array.to_hash(value) => aHash
35
+ # array.to_hash { |element| ... } => aHash
36
36
  #
37
37
  # If neither +value+ nor block is given, converts _array_, taken as an
38
38
  # array of key/value pairs, into a hash, preserving sub-arrays (Thus:
@@ -59,9 +59,9 @@ class Array
59
59
  alias_method :to_h, :to_hash
60
60
 
61
61
  # call-seq:
62
- # array.to_h => aHash
63
- # array.to_h(value) => aHash
64
- # array.to_h { |element| ... } => aHash
62
+ # array.to_hash_opt => aHash
63
+ # array.to_hash_opt(value) => aHash
64
+ # array.to_hash_opt { |element| ... } => aHash
65
65
  #
66
66
  # Same as #to_hash, but slightly optimized for speed. To use this one instead
67
67
  # of #to_hash: <tt>Array.send(:alias_method, :to_h, :to_hash_opt)</tt>.
@@ -4,7 +4,7 @@
4
4
  # A component of ruby-nuggets, some extensions to the Ruby programming #
5
5
  # language. #
6
6
  # #
7
- # Copyright (C) 2007 Jens Wille #
7
+ # Copyright (C) 2007-2008 Jens Wille #
8
8
  # #
9
9
  # Authors: #
10
10
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -28,35 +28,27 @@
28
28
  class Hash
29
29
 
30
30
  # call-seq:
31
- # hash.insert(key, value) => new_hash
32
- # hash.insert(key, value) { |old_value, value| ... } => new_hash
31
+ # hash.insert(other) => new_hash
32
+ # hash.insert(other) { |key, old_value, new_value| ... } => new_hash
33
33
  #
34
- # Inserts +value+ into _hash_ at +key+, while merging existing values at
35
- # +key+ instead of just overwriting. Uses default Hash#merge or block for
36
- # merging.
37
- def insert(key, value, relax = true, &block)
38
- dup.insert!(key, value, relax, &block) || dup
34
+ # Inserts +other+ into _hash_, while merging existing values instead of just
35
+ # overwriting. Uses default Hash#merge or block for merging.
36
+ def insert(other, &block)
37
+ block ||= lambda { |key, old_val, new_val|
38
+ old_val.is_a?(Hash) && new_val.is_a?(Hash) ?
39
+ old_val.merge(new_val, &block) : new_val
40
+ }
41
+
42
+ merge(other, &block)
39
43
  end
40
44
 
41
45
  # call-seq:
42
- # hash.insert!(key, value) => hash
43
- # hash.insert!(key, value) { |old_value, value| ... } => hash
46
+ # hash.insert!(other) => hash
47
+ # hash.insert!(other) { |key, old_value, new_value| ... } => hash
44
48
  #
45
49
  # Destructive version of #insert.
46
- def insert!(key, value, relax = true, &block)
47
- block ||= lambda { |old_val, val| old_val.merge(val) }
48
-
49
- self[key] = begin
50
- block[self[key], value]
51
- rescue NoMethodError, TypeError => err
52
- unless relax
53
- raise err
54
- else
55
- value
56
- end
57
- end
58
-
59
- self
50
+ def insert!(other, &block)
51
+ replace insert(other, &block)
60
52
  end
61
53
 
62
54
  end
@@ -65,9 +57,9 @@ if $0 == __FILE__
65
57
  h = { :a => 0, :b => { :b1 => 1, :b2 => 2 } }
66
58
  p h
67
59
 
68
- p h.insert(:a, -1)
69
- p h.insert(:b, :b3 => 3)
60
+ p h.insert(:a => -1)
61
+ p h.insert(:b => { :b3 => 3 })
70
62
 
71
- h.insert!(:b, :b0 => 0)
63
+ h.insert!(:b => { :b0 => 0 })
72
64
  p h
73
65
  end
@@ -4,7 +4,7 @@
4
4
  # A component of ruby-nuggets, some extensions to the Ruby programming #
5
5
  # language. #
6
6
  # #
7
- # Copyright (C) 2007 Jens Wille #
7
+ # Copyright (C) 2007-2008 Jens Wille #
8
8
  # #
9
9
  # Authors: #
10
10
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -50,7 +50,7 @@ class String
50
50
 
51
51
  # Only +count+ given; require block
52
52
  count = *args
53
- raise(ArgumentError, 'no block given') unless block_given?
53
+ raise LocalJumpError, 'no block given' unless block_given?
54
54
  when 3
55
55
  pattern = args.shift
56
56
 
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 1
7
+ TINY = 2
8
8
 
9
9
  class << self
10
10
 
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.1.1.214
4
+ version: 0.1.2.215
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -24,53 +24,52 @@ extra_rdoc_files:
24
24
  - ChangeLog
25
25
  - README
26
26
  files:
27
- - lib/nuggets/integer/factorial.rb
28
- - lib/nuggets/version.rb
29
- - lib/nuggets/object/singleton_class.rb
30
- - lib/nuggets/object/blank.rb
31
- - lib/nuggets/enumerable/minmax.rb
32
27
  - lib/nuggets/all.rb
28
+ - lib/nuggets/version.rb
29
+ - lib/nuggets/file/which.rb
30
+ - lib/nuggets/integer/factorial.rb
31
+ - lib/nuggets/array/to_hash.rb
32
+ - lib/nuggets/array/shuffle.rb
33
+ - lib/nuggets/array/format.rb
34
+ - lib/nuggets/array/in_order.rb
35
+ - lib/nuggets/array/combination.rb
36
+ - lib/nuggets/array/flatten_once.rb
37
+ - lib/nuggets/array/rand.rb
38
+ - lib/nuggets/array/monotone.rb
39
+ - lib/nuggets/uri/exist.rb
40
+ - lib/nuggets/uri/content_type.rb
41
+ - lib/nuggets/proc/bind.rb
42
+ - lib/nuggets/string/word_wrap.rb
33
43
  - lib/nuggets/string/msub.rb
34
44
  - lib/nuggets/string/case.rb
35
45
  - lib/nuggets/string/evaluate.rb
36
- - lib/nuggets/string/word_wrap.rb
37
46
  - lib/nuggets/string/nsub.rb
38
47
  - lib/nuggets/string/capitalize_first.rb
39
- - lib/nuggets/hash/in_order.rb
40
- - lib/nuggets/hash/insert.rb
41
- - lib/nuggets/proc/bind.rb
42
- - lib/nuggets/array/rand.rb
43
- - lib/nuggets/array/to_hash.rb
44
- - lib/nuggets/array/flatten_once.rb
45
- - lib/nuggets/array/in_order.rb
46
- - lib/nuggets/array/shuffle.rb
47
- - lib/nuggets/array/monotone.rb
48
- - lib/nuggets/array/format.rb
49
- - lib/nuggets/array/combination.rb
48
+ - lib/nuggets/object/blank.rb
49
+ - lib/nuggets/object/singleton_class.rb
50
50
  - lib/nuggets/numeric/signum.rb
51
- - lib/nuggets/util/content_type.rb
52
51
  - lib/nuggets/util/i18n.rb
53
- - lib/nuggets/file/which.rb
54
- - lib/nuggets/uri/content_type.rb
55
- - lib/nuggets/uri/exist.rb
52
+ - lib/nuggets/util/content_type.rb
53
+ - lib/nuggets/enumerable/minmax.rb
54
+ - lib/nuggets/hash/in_order.rb
55
+ - lib/nuggets/hash/insert.rb
56
56
  - COPYING
57
- - HEADER
57
+ - Rakefile
58
58
  - README
59
59
  - ChangeLog
60
- - Rakefile
61
60
  has_rdoc: true
62
61
  homepage: http://prometheus.rubyforge.org/ruby-nuggets
63
62
  post_install_message:
64
63
  rdoc_options:
65
- - --charset
66
- - UTF-8
67
- - --title
68
- - ruby-nuggets Application documentation
69
64
  - --main
70
65
  - README
71
- - --line-numbers
72
66
  - --all
67
+ - --line-numbers
73
68
  - --inline-source
69
+ - --charset
70
+ - UTF-8
71
+ - --title
72
+ - ruby-nuggets Application documentation
74
73
  require_paths:
75
74
  - lib
76
75
  required_ruby_version: !ruby/object:Gem::Requirement
data/HEADER DELETED
@@ -1,27 +0,0 @@
1
- #--
2
- ###############################################################################
3
- # #
4
- # A component of ruby-nuggets, some extensions to the Ruby programming #
5
- # language. #
6
- # #
7
- # Copyright (C) 2007-2008 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
-