ruby-nuggets 0.1.4.231 → 0.1.5.232

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.4
5
+ This documentation refers to ruby-nuggets version 0.1.5
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -0,0 +1,127 @@
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
+
28
+ class String
29
+
30
+ alias_method :sub_without_md, :sub
31
+ alias_method :sub_without_md!, :sub!
32
+ alias_method :gsub_without_md, :gsub
33
+ alias_method :gsub_without_md!, :gsub!
34
+
35
+ # call-seq:
36
+ # str.sub_with_md(pattern) { |match_data| ... } => new_str
37
+ #
38
+ # Just like #sub, but passes the MatchData object instead of the current
39
+ # match string to the block.
40
+ def sub_with_md(pattern, replacement = nil, &block)
41
+ return sub_without_md(pattern, replacement) if replacement
42
+ dup.sub_with_md!(pattern, &block) || dup
43
+ end
44
+
45
+ # call-seq:
46
+ # str.sub_with_md!(pattern) { |match_data| ... } => str or nil
47
+ #
48
+ # Destructive version of #sub_with_md.
49
+ def sub_with_md!(pattern, replacement = nil, &block)
50
+ return sub_without_md!(pattern, replacement) if replacement
51
+ sub_without_md!(pattern) { |match| block[$~] }
52
+ end
53
+
54
+ # call-seq:
55
+ # str.gsub_with_md(pattern) { |match_data| ... } => new_str
56
+ #
57
+ # Just like #gsub, but passes the MatchData object instead of the current
58
+ # match string to the block.
59
+ def gsub_with_md(pattern, replacement = nil, &block)
60
+ return gsub_without_md(pattern, replacement) if replacement
61
+ dup.gsub_with_md!(pattern, &block) || dup
62
+ end
63
+
64
+ # call-seq:
65
+ # str.gsub_with_md!(pattern) { |match_data| ... } => str or nil
66
+ #
67
+ # Destructive version of #gsub_with_md.
68
+ def gsub_with_md!(pattern, replacement = nil, &block)
69
+ return gsub_without_md!(pattern, replacement) if replacement
70
+ gsub_without_md!(pattern) { |match| block[$~] }
71
+ end
72
+
73
+ # call-seq:
74
+ # gimme_match_data!
75
+ #
76
+ # Replaces the traditional substitution methods with their MatchData passing
77
+ # equivalents. USE WITH CAUTION!
78
+ def self.gimme_match_data!
79
+ alias_method :sub, :sub_with_md
80
+ alias_method :sub!, :sub_with_md!
81
+ alias_method :gsub, :gsub_with_md
82
+ alias_method :gsub!, :gsub_with_md!
83
+ end
84
+
85
+ end
86
+
87
+ if $0 == __FILE__
88
+ # stupid example, but it proves the point ;-)
89
+ s = 'Foo, Bar - Baz'
90
+ p s
91
+
92
+ p s.gsub(/\w(\w+)(\W*)/) { |m|
93
+ #p m
94
+ "#{$1.gsub(/[ao]/, 'X')}#{$2}"
95
+ }
96
+
97
+ p s.gsub_with_md(/\w(\w+)(\W*)/) { |md|
98
+ #p md[0]
99
+ "#{md[1].gsub(/[ao]/, 'X')}#{md[2]}"
100
+ }
101
+
102
+ p s.gsub_with_md(/\w(\w+)(\W*)/) { |md|
103
+ #p md[0]
104
+ "#{md[1].gsub_with_md(/[ao]/) { |md2| md2[0].upcase }}#{md[2]}"
105
+ }
106
+
107
+ String.gimme_match_data!
108
+
109
+ p s.gsub(/\w(\w+)(\W*)/) { |m|
110
+ #p m
111
+ begin
112
+ "#{$1.gsub(/[ao]/, 'X')}#{$2}"
113
+ rescue NoMethodError => e
114
+ warn e
115
+ end
116
+ }
117
+
118
+ p s.gsub(/\w(\w+)(\W*)/) { |md|
119
+ #p md[0]
120
+ "#{md[1].gsub(/[ao]/, 'X')}#{md[2]}"
121
+ }
122
+
123
+ p s.gsub(/\w(\w+)(\W*)/) { |md|
124
+ #p md[0]
125
+ "#{md[1].gsub(/[ao]/) { |md2| md2[0].upcase }}#{md[2]}"
126
+ }
127
+ end
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 4
7
+ TINY = 5
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.4.231
4
+ version: 0.1.5.232
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -24,54 +24,54 @@ 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
45
+ - lib/nuggets/string/sub_with_md.rb
35
46
  - lib/nuggets/string/evaluate.rb
36
- - lib/nuggets/string/word_wrap.rb
37
47
  - lib/nuggets/string/nsub.rb
38
48
  - 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
49
+ - lib/nuggets/object/blank.rb
50
+ - lib/nuggets/object/singleton_class.rb
50
51
  - lib/nuggets/numeric/signum.rb
52
+ - lib/nuggets/util/i18n.rb
51
53
  - lib/nuggets/util/ansicolor2css.rb
52
54
  - lib/nuggets/util/content_type.rb
53
- - lib/nuggets/util/i18n.rb
54
- - lib/nuggets/file/which.rb
55
- - lib/nuggets/uri/content_type.rb
56
- - lib/nuggets/uri/exist.rb
55
+ - lib/nuggets/enumerable/minmax.rb
56
+ - lib/nuggets/hash/in_order.rb
57
+ - lib/nuggets/hash/insert.rb
57
58
  - COPYING
58
- - HEADER
59
+ - Rakefile
59
60
  - README
60
61
  - ChangeLog
61
- - Rakefile
62
62
  has_rdoc: true
63
63
  homepage: http://prometheus.rubyforge.org/ruby-nuggets
64
64
  post_install_message:
65
65
  rdoc_options:
66
- - --charset
67
- - UTF-8
66
+ - --inline-source
68
67
  - --title
69
68
  - ruby-nuggets Application documentation
70
69
  - --main
71
70
  - README
72
- - --line-numbers
71
+ - --charset
72
+ - UTF-8
73
73
  - --all
74
- - --inline-source
74
+ - --line-numbers
75
75
  require_paths:
76
76
  - lib
77
77
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements: []
90
90
 
91
91
  rubyforge_project: prometheus
92
- rubygems_version: 1.0.1
92
+ rubygems_version: 1.1.0
93
93
  signing_key:
94
94
  specification_version: 2
95
95
  summary: Some extensions to the Ruby programming language.
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
-