rdx 0.9.0.pre
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.
- checksums.yaml +7 -0
- data/.rdx +20 -0
- data/README +19 -0
- data/bin/rdx +7 -0
- data/examples/minimal/.rdx +8 -0
- data/examples/minimal/README +10 -0
- data/examples/minimal/lib/other_conventions.rb +64 -0
- data/examples/minimal/lib/the_basics.rb +94 -0
- data/examples/minimal/lib/using_directives.rb +66 -0
- data/examples/minimal/rakefile +27 -0
- data/examples/ruby-2.0.0-p0/README +7 -0
- data/examples/ruby-2.0.0-p0/install/core/.rdx +6 -0
- data/examples/ruby-2.0.0-p0/install/core/README +19 -0
- data/examples/ruby-2.0.0-p0/install/core/Rakefile +61 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/array.c.diff +166 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/bignum.c.diff +11 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/class.c.diff +36 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/compar.c.diff +11 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/complex.c.diff +301 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/cont.c.diff +65 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/dir.c.diff +147 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/re.rdoc.diff +328 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/security.rdoc.diff +8 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/standard_library.rdoc.diff +0 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax.rdoc.diff +0 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/assignment.rdoc.diff +160 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/calling_methods.rdoc.diff +130 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/control_expressions.rdoc.diff +254 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/exceptions.rdoc.diff +0 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/literals.rdoc.diff +54 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/methods.rdoc.diff +157 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/miscellaneous.rdoc.diff +91 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/modules_and_classes.rdoc.diff +161 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/precedence.rdoc.diff +8 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/refinements.rdoc.diff +146 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/encoding.c.diff +276 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/enum.c.diff +281 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/enumerator.c.diff +479 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/error.c.diff +143 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/eval.c.diff +47 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/eval_jump.c.diff +23 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/file.c.diff +752 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/gc.c.diff +195 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/hash.c.diff +84 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/iseq.c.diff +354 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/load.c.diff +53 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/marshal.c.diff +98 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/math.c.diff +110 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/numeric.c.diff +103 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/object.c.diff +295 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/pack.c.diff +18 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/parse.y.diff +23 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/proc.c.diff +155 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/random.c.diff +126 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/range.c.diff +49 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/rational.c.diff +312 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/re.c.diff +207 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/ruby.c.diff +21 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/signal.c.diff +67 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/sprintf.c.diff +29 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/string.c.diff +73 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/struct.c.diff +20 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/time.c.diff +691 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/transcode.c.diff +435 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/variable.c.diff +62 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/vm_backtrace.c.diff +164 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/vm_eval.c.diff +99 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/vm_method.c.diff +17 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/vm_trace.c.diff +393 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/.rdx +6 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/README +19 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/Rakefile +53 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/abbrev.rb.diff +77 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/base64.rb.diff +42 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/benchmark.rb.diff +144 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/cmath.rb.diff +52 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/forwardable.rb.diff +150 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/mathn.rb.diff +58 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/matrix.rb.diff +657 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/observer.rb.diff +31 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/optparse.rb.diff +147 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/ostruct.rb.diff +78 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/prime.rb.diff +52 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/pstore.rb.diff +110 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/scanf.rb.diff +100 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/securerandom.rb.diff +144 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/set.rb.diff +637 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/shellwords.rb.diff +66 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/singleton.rb.diff +37 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/tempfile.rb.diff +104 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/thread.rb.diff +38 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/time.rb.diff +140 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/tmpdir.rb.diff +52 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/uri.rb.diff +39 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/uri/common.rb.diff +237 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/weakref.rb.diff +36 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/yaml/store.rb.diff +27 -0
- data/examples/ruby-2.0.0-p0/rakefile +165 -0
- data/lib/rdx.rb +331 -0
- data/lib/rdx/assertions.rb +484 -0
- data/lib/rdx/binding.rb +151 -0
- data/lib/rdx/code_object.rb +598 -0
- data/lib/rdx/comment.rb +338 -0
- data/lib/rdx/convention.rb +1174 -0
- data/lib/rdx/directive.rb +1432 -0
- data/lib/rdx/example.rb +679 -0
- data/lib/rdx/generator.rb +112 -0
- data/lib/rdx/generator/rdoc.rb +1006 -0
- data/lib/rdx/options.rb +359 -0
- data/lib/rdx/plain_text.rb +65 -0
- data/lib/rdx/reporter.rb +421 -0
- data/lib/rdx/ruby_lex.rb +324 -0
- data/lib/rdx/runner.rb +309 -0
- data/lib/rdx/source_file.rb +94 -0
- data/lib/rdx/specification.rb +194 -0
- data/lib/rdx/statement.rb +248 -0
- data/lib/rdx/store.rb +119 -0
- data/lib/rdx/task.rb +361 -0
- data/lib/rdx/text.rb +688 -0
- data/lib/rdx/version.rb +15 -0
- data/rakefile +64 -0
- metadata +203 -0
@@ -0,0 +1,328 @@
|
|
1
|
+
--- core/orig/doc/re.rdoc 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/doc/re.rdoc 2015-06-28 09:45:49 +0000
|
3
|
+
@@ -11,7 +11,7 @@
|
4
|
+
example:
|
5
|
+
|
6
|
+
/hay/ =~ 'haystack' #=> 0
|
7
|
+
- /y/.match('haystack') #=> #<MatchData "y">
|
8
|
+
+ /y/.match('haystack') # > #<MatchData "y">
|
9
|
+
|
10
|
+
If a string contains the pattern it is said to <i>match</i>. A literal
|
11
|
+
string matches itself.
|
12
|
+
@@ -19,7 +19,7 @@
|
13
|
+
# 'haystack' does not contain the pattern 'needle', so doesn't match.
|
14
|
+
/needle/.match('haystack') #=> nil
|
15
|
+
# 'haystack' does contain the pattern 'hay', so it matches
|
16
|
+
- /hay/.match('haystack') #=> #<MatchData "hay">
|
17
|
+
+ /hay/.match('haystack') # > #<MatchData "hay">
|
18
|
+
|
19
|
+
Specifically, <tt>/st/</tt> requires that the string contains the letter
|
20
|
+
_s_ followed by the letter _t_, so it matches _haystack_, also.
|
21
|
+
@@ -52,7 +52,7 @@
|
22
|
+
|
23
|
+
#match method return a MatchData object :
|
24
|
+
|
25
|
+
- /st/.match('haystack') #=> #<MatchData "st">
|
26
|
+
+ /st/.match('haystack') # > #<MatchData "st">
|
27
|
+
|
28
|
+
== Metacharacters and Escapes
|
29
|
+
|
30
|
+
@@ -62,20 +62,23 @@
|
31
|
+
pattern. To match them literally they must be backslash-escaped. To match
|
32
|
+
a backslash literally backslash-escape that: <tt>\\\\\\</tt>.
|
33
|
+
|
34
|
+
- /1 \+ 2 = 3\?/.match('Does 1 + 2 = 3?') #=> #<MatchData "1 + 2 = 3?">
|
35
|
+
+ /1 \+ 2 = 3\?/.match('Does 1 + 2 = 3?') # > #<MatchData "1 + 2 = 3?">
|
36
|
+
|
37
|
+
Patterns behave like double-quoted strings so can contain the same
|
38
|
+
backslash escapes.
|
39
|
+
|
40
|
+
+:rdx: if Encoding.default_external == Encoding::UTF_8
|
41
|
+
+:rdx: # otherwise istead of the char "\u6771" it gives "\\u6771"
|
42
|
+
/\s\u{6771 4eac 90fd}/.match("Go to 東京都")
|
43
|
+
- #=> #<MatchData " 東京都">
|
44
|
+
+ # > #<MatchData " 東京都">
|
45
|
+
|
46
|
+
Arbitrary Ruby expressions can be embedded into patterns with the
|
47
|
+
<tt>#{...}</tt> construct.
|
48
|
+
|
49
|
+
+:rdx: if Encoding.default_external == Encoding::UTF_8
|
50
|
+
place = "東京都"
|
51
|
+
/#{place}/.match("Go to 東京都")
|
52
|
+
- #=> #<MatchData "東京都">
|
53
|
+
+ # > #<MatchData "東京都">
|
54
|
+
|
55
|
+
== Character Classes
|
56
|
+
|
57
|
+
@@ -84,7 +87,7 @@
|
58
|
+
match. <tt>/[ab]/</tt> means _a_ or _b_, as opposed to <tt>/ab/</tt> which
|
59
|
+
means _a_ followed by _b_.
|
60
|
+
|
61
|
+
- /W[aeiou]rd/.match("Word") #=> #<MatchData "Word">
|
62
|
+
+ /W[aeiou]rd/.match("Word") # > #<MatchData "Word">
|
63
|
+
|
64
|
+
Within a character class the hyphen (<tt>-</tt>) is a metacharacter
|
65
|
+
denoting an inclusive range of characters. <tt>[abcd]</tt> is equivalent
|
66
|
+
@@ -93,13 +96,13 @@
|
67
|
+
ranges or individual characters appear inside a character class is
|
68
|
+
irrelevant.
|
69
|
+
|
70
|
+
- /[0-9a-f]/.match('9f') #=> #<MatchData "9">
|
71
|
+
- /[9f]/.match('9f') #=> #<MatchData "9">
|
72
|
+
+ /[0-9a-f]/.match('9f') # > #<MatchData "9">
|
73
|
+
+ /[9f]/.match('9f') # > #<MatchData "9">
|
74
|
+
|
75
|
+
If the first character of a character class is a caret (<tt>^</tt>) the
|
76
|
+
class is inverted: it matches any character _except_ those named.
|
77
|
+
|
78
|
+
- /[^a-eg-z]/.match('f') #=> #<MatchData "f">
|
79
|
+
+ /[^a-eg-z]/.match('f') # > #<MatchData "f">
|
80
|
+
|
81
|
+
A character class may contain another character class. By itself this
|
82
|
+
isn't useful because <tt>[a-z[0-9]]</tt> describes the same set as
|
83
|
+
@@ -107,7 +110,7 @@
|
84
|
+
operator which performs set intersection on its arguments. The two can be
|
85
|
+
combined as follows:
|
86
|
+
|
87
|
+
- /[a-w&&[^c-g]z]/ # ([a-w] AND ([^c-g] OR z))
|
88
|
+
+ /[a-w&&[^c-g]z]/ # means [a-w] AND ([^c-g] OR z)
|
89
|
+
# This is equivalent to:
|
90
|
+
/[abh-w]/
|
91
|
+
|
92
|
+
@@ -153,10 +156,12 @@
|
93
|
+
<i>Connector_Punctuation</i>
|
94
|
+
* <tt>/[[:ascii:]]/</tt> - A character in the ASCII character set
|
95
|
+
|
96
|
+
+:rdx: if Encoding.default_external == Encoding::UTF_8
|
97
|
+
# U+06F2 is "EXTENDED ARABIC-INDIC DIGIT TWO"
|
98
|
+
- /[[:digit:]]/.match("\u06F2") #=> #<MatchData "\u{06F2}">
|
99
|
+
- /[[:upper:]][[:lower:]]/.match("Hello") #=> #<MatchData "He">
|
100
|
+
- /[[:xdigit:]][[:xdigit:]]/.match("A6") #=> #<MatchData "A6">
|
101
|
+
+ /[[:digit:]]/.match("\u06F2").inspect #=> %Q{#<MatchData "\u{06F2}">}
|
102
|
+
+:rdx:
|
103
|
+
+ /[[:upper:]][[:lower:]]/.match("Hello") # > #<MatchData "He">
|
104
|
+
+ /[[:xdigit:]][[:xdigit:]]/.match("A6") # > #<MatchData "A6">
|
105
|
+
|
106
|
+
== Repetition
|
107
|
+
|
108
|
+
@@ -175,7 +180,7 @@
|
109
|
+
|
110
|
+
# At least one uppercase character ('H'), at least one lowercase
|
111
|
+
# character ('e'), two 'l' characters, then one 'o'
|
112
|
+
- "Hello".match(/[[:upper:]]+[[:lower:]]+l{2}o/) #=> #<MatchData "Hello">
|
113
|
+
+ "Hello".match(/[[:upper:]]+[[:lower:]]+l{2}o/) # > #<MatchData "Hello">
|
114
|
+
|
115
|
+
Repetition is <i>greedy</i> by default: as many occurrences as possible
|
116
|
+
are matched while still allowing the overall match to succeed. By
|
117
|
+
@@ -186,8 +191,8 @@
|
118
|
+
# Both patterns below match the string. The first uses a greedy
|
119
|
+
# quantifier so '.+' matches '<a><b>'; the second uses a lazy
|
120
|
+
# quantifier so '.+?' matches '<a>'.
|
121
|
+
- /<.+>/.match("<a><b>") #=> #<MatchData "<a><b>">
|
122
|
+
- /<.+?>/.match("<a><b>") #=> #<MatchData "<a>">
|
123
|
+
+ /<.+>/.match("<a><b>") # > #<MatchData "<a><b>">
|
124
|
+
+ /<.+?>/.match("<a><b>") # > #<MatchData "<a>">
|
125
|
+
|
126
|
+
A quantifier followed by <tt>+</tt> matches <i>possessively</i>: once it
|
127
|
+
has matched it does not backtrack. They behave like greedy quantifiers,
|
128
|
+
@@ -205,7 +210,7 @@
|
129
|
+
# 'at' is captured by the first group of parentheses, then referred to
|
130
|
+
# later with \1
|
131
|
+
/[csh](..) [csh]\1 in/.match("The cat sat in the hat")
|
132
|
+
- #=> #<MatchData "cat sat in" 1:"at">
|
133
|
+
+ # > #<MatchData "cat sat in" 1:"at">
|
134
|
+
# Regexp#match returns a MatchData object which makes the captured
|
135
|
+
# text available with its #[] method.
|
136
|
+
/[csh](..) [csh]\1 in/.match("The cat sat in the hat")[1] #=> 'at'
|
137
|
+
@@ -215,14 +220,14 @@
|
138
|
+
constructs.
|
139
|
+
|
140
|
+
/\$(?<dollars>\d+)\.(?<cents>\d+)/.match("$3.67")
|
141
|
+
- => #<MatchData "$3.67" dollars:"3" cents:"67">
|
142
|
+
+ # > #<MatchData "$3.67" dollars:"3" cents:"67">
|
143
|
+
/\$(?<dollars>\d+)\.(?<cents>\d+)/.match("$3.67")[:dollars] #=> "3"
|
144
|
+
|
145
|
+
Named groups can be backreferenced with <tt>\k<</tt><i>name</i><tt>></tt>,
|
146
|
+
where _name_ is the group name.
|
147
|
+
|
148
|
+
/(?<vowel>[aeiou]).\k<vowel>.\k<vowel>/.match('ototomy')
|
149
|
+
- #=> #<MatchData "ototo" vowel:"o">
|
150
|
+
+ # > #<MatchData "ototo" vowel:"o">
|
151
|
+
|
152
|
+
*Note*: A regexp can't use named backreferences and numbered
|
153
|
+
backreferences simultaneously.
|
154
|
+
@@ -241,11 +246,11 @@
|
155
|
+
|
156
|
+
# The pattern below matches a vowel followed by 2 word characters:
|
157
|
+
# 'aen'
|
158
|
+
- /[aeiou]\w{2}/.match("Caenorhabditis elegans") #=> #<MatchData "aen">
|
159
|
+
+ /[aeiou]\w{2}/.match("Caenorhabditis elegans") # > #<MatchData "aen">
|
160
|
+
# Whereas the following pattern matches a vowel followed by a word
|
161
|
+
# character, twice, i.e. <tt>[aeiou]\w[aeiou]\w</tt>: 'enor'.
|
162
|
+
/([aeiou]\w){2}/.match("Caenorhabditis elegans")
|
163
|
+
- #=> #<MatchData "enor" 1:"or">
|
164
|
+
+ # > #<MatchData "enor" 1:"or">
|
165
|
+
|
166
|
+
The <tt>(?:</tt>...<tt>)</tt> construct provides grouping without
|
167
|
+
capturing. That is, it combines the terms it contains into an atomic whole
|
168
|
+
@@ -255,12 +260,12 @@
|
169
|
+
# The group of parentheses captures 'n' and the second 'ti'. The
|
170
|
+
# second group is referred to later with the backreference \2
|
171
|
+
/I(n)ves(ti)ga\2ons/.match("Investigations")
|
172
|
+
- #=> #<MatchData "Investigations" 1:"n" 2:"ti">
|
173
|
+
+ # > #<MatchData "Investigations" 1:"n" 2:"ti">
|
174
|
+
# The first group of parentheses is now made non-capturing with '?:',
|
175
|
+
# so it still matches 'n', but doesn't create the backreference. Thus,
|
176
|
+
# the backreference \1 now refers to 'ti'.
|
177
|
+
/I(?:n)ves(ti)ga\1ons/.match("Investigations")
|
178
|
+
- #=> #<MatchData "Investigations" 1:"ti">
|
179
|
+
+ # > #<MatchData "Investigations" 1:"ti">
|
180
|
+
|
181
|
+
=== Atomic Grouping
|
182
|
+
|
183
|
+
@@ -278,7 +283,7 @@
|
184
|
+
# overall match to fail, so the text matched by <tt>.*</tt> is
|
185
|
+
# backtracked by one position, which leaves the final character of the
|
186
|
+
# string available to match <tt>"</tt>
|
187
|
+
- /".*"/.match('"Quote"') #=> #<MatchData "\"Quote\"">
|
188
|
+
+ /".*"/.match('"Quote"') # > #<MatchData "\"Quote\"">
|
189
|
+
# If <tt>.*</tt> is grouped atomically, it refuses to backtrack
|
190
|
+
# <i>Quote"</i>, even though this means that the overall match fails
|
191
|
+
/"(?>.*)"/.match('"Quote"') #=> nil
|
192
|
+
@@ -330,8 +335,8 @@
|
193
|
+
a single one that matches either of the expressions. Each expression is an
|
194
|
+
<i>alternative</i>.
|
195
|
+
|
196
|
+
- /\w(and|or)\w/.match("Feliformia") #=> #<MatchData "form" 1:"or">
|
197
|
+
- /\w(and|or)\w/.match("furandi") #=> #<MatchData "randi" 1:"and">
|
198
|
+
+ /\w(and|or)\w/.match("Feliformia") # > #<MatchData "form" 1:"or">
|
199
|
+
+ /\w(and|or)\w/.match("furandi") # > #<MatchData "randi" 1:"and">
|
200
|
+
/\w(and|or)\w/.match("dissemblance") #=> nil
|
201
|
+
|
202
|
+
== Character Properties
|
203
|
+
@@ -426,16 +431,17 @@
|
204
|
+
<i>Tamil</i>, <i>Telugu</i>, <i>Thaana</i>, <i>Thai</i>, <i>Tibetan</i>,
|
205
|
+
<i>Tifinagh</i>, <i>Ugaritic</i>, <i>Vai</i>, and <i>Yi</i>.
|
206
|
+
|
207
|
+
+:rdx: if Encoding.default_external == Encoding::UTF_8
|
208
|
+
# Unicode codepoint U+06E9 is named "ARABIC PLACE OF SAJDAH" and
|
209
|
+
# belongs to the Arabic script.
|
210
|
+
- /\p{Arabic}/.match("\u06E9") #=> #<MatchData "\u06E9">
|
211
|
+
+ /\p{Arabic}/.match("\u06E9").inspect #=> %Q{#<MatchData "\u06E9">}
|
212
|
+
|
213
|
+
All character properties can be inverted by prefixing their name with a
|
214
|
+
caret (<tt>^</tt>).
|
215
|
+
|
216
|
+
# Letter 'A' is not in the Unicode Ll (Letter; Lowercase) category, so
|
217
|
+
# this match succeeds
|
218
|
+
- /\p{^Ll}/.match("A") #=> #<MatchData "A">
|
219
|
+
+ /\p{^Ll}/.match("A") # > #<MatchData "A">
|
220
|
+
|
221
|
+
== Anchors
|
222
|
+
|
223
|
+
@@ -466,23 +472,23 @@
|
224
|
+
<i>pat</i>, but doesn't include those characters in the matched text
|
225
|
+
|
226
|
+
# If a pattern isn't anchored it can begin at any point in the string
|
227
|
+
- /real/.match("surrealist") #=> #<MatchData "real">
|
228
|
+
+ /real/.match("surrealist") # > #<MatchData "real">
|
229
|
+
# Anchoring the pattern to the beginning of the string forces the
|
230
|
+
# match to start there. 'real' doesn't occur at the beginning of the
|
231
|
+
# string, so now the match fails
|
232
|
+
/\Areal/.match("surrealist") #=> nil
|
233
|
+
# The match below fails because although 'Demand' contains 'and', the
|
234
|
+
- pattern does not occur at a word boundary.
|
235
|
+
+ # pattern does not occur at a word boundary.
|
236
|
+
/\band/.match("Demand")
|
237
|
+
# Whereas in the following example 'and' has been anchored to a
|
238
|
+
# non-word boundary so instead of matching the first 'and' it matches
|
239
|
+
# from the fourth letter of 'demand' instead
|
240
|
+
- /\Band.+/.match("Supply and demand curve") #=> #<MatchData "and curve">
|
241
|
+
+ /\Band.+/.match("Supply and demand curve") # > #<MatchData "and curve">
|
242
|
+
# The pattern below uses positive lookahead and positive lookbehind to
|
243
|
+
# match text appearing in <b></b> tags without including the tags in the
|
244
|
+
# match
|
245
|
+
/(?<=<b>)\w+(?=<\/b>)/.match("Fortune favours the <b>bold</b>")
|
246
|
+
- #=> #<MatchData "bold">
|
247
|
+
+ # > #<MatchData "bold">
|
248
|
+
|
249
|
+
== Options
|
250
|
+
|
251
|
+
@@ -500,8 +506,8 @@
|
252
|
+
enables options <i>on</i>, and disables options <i>off</i> for the
|
253
|
+
expression enclosed by the parentheses.
|
254
|
+
|
255
|
+
- /a(?i:b)c/.match('aBc') #=> #<MatchData "aBc">
|
256
|
+
- /a(?i:b)c/.match('abc') #=> #<MatchData "abc">
|
257
|
+
+ /a(?i:b)c/.match('aBc') # > #<MatchData "aBc">
|
258
|
+
+ /a(?i:b)c/.match('abc') # > #<MatchData "abc">
|
259
|
+
|
260
|
+
Options may also be used with <tt>Regexp.new</tt>:
|
261
|
+
|
262
|
+
@@ -525,7 +531,7 @@
|
263
|
+
[[:digit:]]+ # 1 or more digits after the decimal point
|
264
|
+
)? # The decimal point and following digits are optional
|
265
|
+
\Z/x
|
266
|
+
- float_pat.match('3.14') #=> #<MatchData "3.14" 1:".14">
|
267
|
+
+ float_pat.match('3.14') # > #<MatchData "3.14" 1:".14">
|
268
|
+
|
269
|
+
*Note*: To match whitespace in an <tt>x</tt> pattern use an escape such as
|
270
|
+
<tt>\s</tt> or <tt>\p{Space}</tt>.
|
271
|
+
@@ -559,7 +565,10 @@
|
272
|
+
|
273
|
+
r = Regexp.new("a".force_encoding("iso-8859-1"),Regexp::FIXEDENCODING)
|
274
|
+
r =~"a\u3042"
|
275
|
+
- #=> Encoding::CompatibilityError: incompatible encoding regexp match
|
276
|
+
+
|
277
|
+
+raises the exception:
|
278
|
+
+
|
279
|
+
+ Encoding::CompatibilityError: incompatible encoding regexp match
|
280
|
+
(ISO-8859-1 regexp with UTF-8 string)
|
281
|
+
|
282
|
+
== Special global variables
|
283
|
+
@@ -575,9 +584,9 @@
|
284
|
+
|
285
|
+
Example:
|
286
|
+
|
287
|
+
- m = /s(\w{2}).*(c)/.match('haystack') #=> #<MatchData "stac" 1:"ta" 2:"c">
|
288
|
+
- $~ #=> #<MatchData "stac" 1:"ta" 2:"c">
|
289
|
+
- Regexp.latch_match #=> #<MatchData "stac" 1:"ta" 2:"c">
|
290
|
+
+ m = /s(\w{2}).*(c)/.match('haystack') # > #<MatchData "stac" 1:"ta" 2:"c">
|
291
|
+
+ $~ # > #<MatchData "stac" 1:"ta" 2:"c">
|
292
|
+
+ Regexp.last_match # > #<MatchData "stac" 1:"ta" 2:"c">
|
293
|
+
|
294
|
+
$& #=> "stac"
|
295
|
+
# same as m[0]
|
296
|
+
@@ -611,10 +620,11 @@
|
297
|
+
|
298
|
+
/(b|a)/ =~ s #=> 0
|
299
|
+
/(b|a+)/ =~ s #=> 0
|
300
|
+
- /(b|a+)*\/ =~ s #=> 0
|
301
|
+
+ /(b|a+)*/ =~ s #=> 0
|
302
|
+
|
303
|
+
However, the following pattern takes appreciably longer:
|
304
|
+
|
305
|
+
+:rdx: is_slow
|
306
|
+
/(b|a+)*c/ =~ s #=> 26
|
307
|
+
|
308
|
+
This happens because an atom in the regexp is quantified by both an
|
309
|
+
@@ -626,14 +636,17 @@
|
310
|
+
can be fixed by use of atomic grouping, which prevents the unnecessary
|
311
|
+
backtracking:
|
312
|
+
|
313
|
+
+:rdx: is_slow
|
314
|
+
(start = Time.now) && /(b|a+)*c/ =~ s && (Time.now - start)
|
315
|
+
- #=> 24.702736882
|
316
|
+
+ #-> 24.702736882
|
317
|
+
+
|
318
|
+
(start = Time.now) && /(?>b|a+)*c/ =~ s && (Time.now - start)
|
319
|
+
- #=> 0.000166571
|
320
|
+
+ #-> 0.000166571
|
321
|
+
|
322
|
+
A similar case is typified by the following example, which takes
|
323
|
+
approximately 60 seconds to execute for me:
|
324
|
+
|
325
|
+
+:rdx: is_slow
|
326
|
+
# Match a string of 29 <i>a</i>s against a pattern of 29 optional
|
327
|
+
# <i>a</i>s followed by 29 mandatory <i>a</i>s.
|
328
|
+
Regexp.new('a?' * 29 + 'a' * 29) =~ 'a' * 29
|
@@ -0,0 +1,8 @@
|
|
1
|
+
--- core/orig/doc/security.rdoc 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/doc/security.rdoc 2015-06-11 07:51:46 +0000
|
3
|
+
@@ -1,4 +1,5 @@
|
4
|
+
= Ruby Security
|
5
|
+
+:rdx: off
|
6
|
+
|
7
|
+
The Ruby programming language is large and complex and there are many security
|
8
|
+
pitfalls often encountered by newcomers and experienced Rubyists alike.
|
File without changes
|
File without changes
|
@@ -0,0 +1,160 @@
|
|
1
|
+
--- core/orig/doc/syntax/assignment.rdoc 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/doc/syntax/assignment.rdoc 2015-06-25 13:32:09 +0000
|
3
|
+
@@ -27,6 +27,7 @@
|
4
|
+
rest of the scope are considered local variables.
|
5
|
+
|
6
|
+
Here is an example:
|
7
|
+
+:rdx: new_binding
|
8
|
+
|
9
|
+
1.times do
|
10
|
+
a = 1
|
11
|
+
@@ -35,7 +36,7 @@
|
12
|
+
|
13
|
+
puts "no local variables outside the block" if local_variables.empty?
|
14
|
+
|
15
|
+
-This prints:
|
16
|
+
+Produces:
|
17
|
+
|
18
|
+
local variables in the block: a
|
19
|
+
no local variables outside the block
|
20
|
+
@@ -44,6 +45,7 @@
|
21
|
+
not leak to the surrounding scope.
|
22
|
+
|
23
|
+
Variables defined in an outer scope appear inner scope:
|
24
|
+
+:rdx: new_binding
|
25
|
+
|
26
|
+
a = 0
|
27
|
+
|
28
|
+
@@ -51,7 +53,7 @@
|
29
|
+
puts "local variables: #{local_variables.join ", "}"
|
30
|
+
end
|
31
|
+
|
32
|
+
-This prints:
|
33
|
+
+Produces:
|
34
|
+
|
35
|
+
local variables: a
|
36
|
+
|
37
|
+
@@ -72,6 +74,7 @@
|
38
|
+
|
39
|
+
The local variable is created when the parser encounters the assignment, not
|
40
|
+
when the assignment occurs:
|
41
|
+
+:rdx: new_binding
|
42
|
+
|
43
|
+
a = 0 if false # does not assign to a
|
44
|
+
|
45
|
+
@@ -96,11 +99,16 @@
|
46
|
+
receiver may raise a NameError if the method's visibility is not public.
|
47
|
+
|
48
|
+
Another commonly confusing case is when using a modifier +if+:
|
49
|
+
+:rdx: new_binding
|
50
|
+
|
51
|
+
p a if a = 0.zero?
|
52
|
+
|
53
|
+
-Rather than printing "true" you receive a NameError, "undefined local variable
|
54
|
+
-or method `a'". Since ruby parses the bare +a+ left of the +if+ first and has
|
55
|
+
+Rather than printing "true" you receive the exception
|
56
|
+
+:rdx: error
|
57
|
+
+
|
58
|
+
+ undefined local variable or method `a' (NameError)
|
59
|
+
+
|
60
|
+
+Since ruby parses the bare +a+ left of the +if+ first and has
|
61
|
+
not yet seen an assignment to +a+ it assumes you wish to call a method. Ruby
|
62
|
+
then sees the assignment to +a+ and will assume you are referencing a local
|
63
|
+
method.
|
64
|
+
@@ -110,6 +118,7 @@
|
65
|
+
method.
|
66
|
+
|
67
|
+
== Instance Variables
|
68
|
+
+:rdx: new_binding
|
69
|
+
|
70
|
+
Instance variables are shared across all methods for the same object.
|
71
|
+
|
72
|
+
@@ -144,6 +153,7 @@
|
73
|
+
only for the same object.
|
74
|
+
|
75
|
+
== Class Variables
|
76
|
+
+:rdx: new_binding
|
77
|
+
|
78
|
+
Class variables are shared between a class, its subclasses and its instances.
|
79
|
+
|
80
|
+
@@ -176,7 +186,7 @@
|
81
|
+
puts "A value: #{a.value}"
|
82
|
+
puts "B value: #{b.value}"
|
83
|
+
|
84
|
+
-This prints:
|
85
|
+
+Produces:
|
86
|
+
|
87
|
+
A value: 0
|
88
|
+
B value: 0
|
89
|
+
@@ -202,7 +212,7 @@
|
90
|
+
puts "A value: #{a.value}"
|
91
|
+
puts "B value: #{b.value}"
|
92
|
+
|
93
|
+
-This prints:
|
94
|
+
+Produces:
|
95
|
+
|
96
|
+
update A
|
97
|
+
A value: 1
|
98
|
+
@@ -220,6 +230,7 @@
|
99
|
+
try not to confuse class and instance variables.
|
100
|
+
|
101
|
+
== Global Variables
|
102
|
+
+:rdx: new_binding
|
103
|
+
|
104
|
+
Global variables are accessible everywhere.
|
105
|
+
|
106
|
+
@@ -244,8 +255,11 @@
|
107
|
+
C.new.my_method
|
108
|
+
|
109
|
+
puts "at top-level, $global: #{$global}, $other_global: #{$other_global}"
|
110
|
+
+-- rdx
|
111
|
+
+ $global = nil
|
112
|
+
+++
|
113
|
+
|
114
|
+
-This prints:
|
115
|
+
+Produces:
|
116
|
+
|
117
|
+
in a class: 0
|
118
|
+
in a method: 0
|
119
|
+
@@ -259,6 +273,7 @@
|
120
|
+
for details.
|
121
|
+
|
122
|
+
== Assignment Methods
|
123
|
+
+:rdx: new_binding
|
124
|
+
|
125
|
+
You can define methods that will behave like assignment, for example:
|
126
|
+
|
127
|
+
@@ -294,7 +309,7 @@
|
128
|
+
|
129
|
+
C.new.my_method
|
130
|
+
|
131
|
+
-This prints:
|
132
|
+
+Produces:
|
133
|
+
|
134
|
+
local_variables: value
|
135
|
+
@value: nil
|
136
|
+
@@ -314,12 +329,13 @@
|
137
|
+
|
138
|
+
C.new.my_method
|
139
|
+
|
140
|
+
-This prints:
|
141
|
+
+Produces:
|
142
|
+
|
143
|
+
local_variables:
|
144
|
+
@value: 42
|
145
|
+
|
146
|
+
== Abbreviated Assignment
|
147
|
+
+:rdx: new_binding
|
148
|
+
|
149
|
+
You can mix several of the operators and assignment. To add 1 to an object
|
150
|
+
you can write:
|
151
|
+
@@ -398,6 +414,9 @@
|
152
|
+
self.value, $global = 1, 2 # prints {:assigned=>1}
|
153
|
+
|
154
|
+
p $global # prints 2
|
155
|
+
+-- rdx
|
156
|
+
+ $global = nil
|
157
|
+
+++
|
158
|
+
|
159
|
+
You can use multiple assignment to swap two values in-place:
|
160
|
+
|