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.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.rdx +20 -0
  3. data/README +19 -0
  4. data/bin/rdx +7 -0
  5. data/examples/minimal/.rdx +8 -0
  6. data/examples/minimal/README +10 -0
  7. data/examples/minimal/lib/other_conventions.rb +64 -0
  8. data/examples/minimal/lib/the_basics.rb +94 -0
  9. data/examples/minimal/lib/using_directives.rb +66 -0
  10. data/examples/minimal/rakefile +27 -0
  11. data/examples/ruby-2.0.0-p0/README +7 -0
  12. data/examples/ruby-2.0.0-p0/install/core/.rdx +6 -0
  13. data/examples/ruby-2.0.0-p0/install/core/README +19 -0
  14. data/examples/ruby-2.0.0-p0/install/core/Rakefile +61 -0
  15. data/examples/ruby-2.0.0-p0/install/core/diffs/array.c.diff +166 -0
  16. data/examples/ruby-2.0.0-p0/install/core/diffs/bignum.c.diff +11 -0
  17. data/examples/ruby-2.0.0-p0/install/core/diffs/class.c.diff +36 -0
  18. data/examples/ruby-2.0.0-p0/install/core/diffs/compar.c.diff +11 -0
  19. data/examples/ruby-2.0.0-p0/install/core/diffs/complex.c.diff +301 -0
  20. data/examples/ruby-2.0.0-p0/install/core/diffs/cont.c.diff +65 -0
  21. data/examples/ruby-2.0.0-p0/install/core/diffs/dir.c.diff +147 -0
  22. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/re.rdoc.diff +328 -0
  23. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/security.rdoc.diff +8 -0
  24. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/standard_library.rdoc.diff +0 -0
  25. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax.rdoc.diff +0 -0
  26. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/assignment.rdoc.diff +160 -0
  27. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/calling_methods.rdoc.diff +130 -0
  28. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/control_expressions.rdoc.diff +254 -0
  29. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/exceptions.rdoc.diff +0 -0
  30. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/literals.rdoc.diff +54 -0
  31. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/methods.rdoc.diff +157 -0
  32. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/miscellaneous.rdoc.diff +91 -0
  33. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/modules_and_classes.rdoc.diff +161 -0
  34. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/precedence.rdoc.diff +8 -0
  35. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/refinements.rdoc.diff +146 -0
  36. data/examples/ruby-2.0.0-p0/install/core/diffs/encoding.c.diff +276 -0
  37. data/examples/ruby-2.0.0-p0/install/core/diffs/enum.c.diff +281 -0
  38. data/examples/ruby-2.0.0-p0/install/core/diffs/enumerator.c.diff +479 -0
  39. data/examples/ruby-2.0.0-p0/install/core/diffs/error.c.diff +143 -0
  40. data/examples/ruby-2.0.0-p0/install/core/diffs/eval.c.diff +47 -0
  41. data/examples/ruby-2.0.0-p0/install/core/diffs/eval_jump.c.diff +23 -0
  42. data/examples/ruby-2.0.0-p0/install/core/diffs/file.c.diff +752 -0
  43. data/examples/ruby-2.0.0-p0/install/core/diffs/gc.c.diff +195 -0
  44. data/examples/ruby-2.0.0-p0/install/core/diffs/hash.c.diff +84 -0
  45. data/examples/ruby-2.0.0-p0/install/core/diffs/iseq.c.diff +354 -0
  46. data/examples/ruby-2.0.0-p0/install/core/diffs/load.c.diff +53 -0
  47. data/examples/ruby-2.0.0-p0/install/core/diffs/marshal.c.diff +98 -0
  48. data/examples/ruby-2.0.0-p0/install/core/diffs/math.c.diff +110 -0
  49. data/examples/ruby-2.0.0-p0/install/core/diffs/numeric.c.diff +103 -0
  50. data/examples/ruby-2.0.0-p0/install/core/diffs/object.c.diff +295 -0
  51. data/examples/ruby-2.0.0-p0/install/core/diffs/pack.c.diff +18 -0
  52. data/examples/ruby-2.0.0-p0/install/core/diffs/parse.y.diff +23 -0
  53. data/examples/ruby-2.0.0-p0/install/core/diffs/proc.c.diff +155 -0
  54. data/examples/ruby-2.0.0-p0/install/core/diffs/random.c.diff +126 -0
  55. data/examples/ruby-2.0.0-p0/install/core/diffs/range.c.diff +49 -0
  56. data/examples/ruby-2.0.0-p0/install/core/diffs/rational.c.diff +312 -0
  57. data/examples/ruby-2.0.0-p0/install/core/diffs/re.c.diff +207 -0
  58. data/examples/ruby-2.0.0-p0/install/core/diffs/ruby.c.diff +21 -0
  59. data/examples/ruby-2.0.0-p0/install/core/diffs/signal.c.diff +67 -0
  60. data/examples/ruby-2.0.0-p0/install/core/diffs/sprintf.c.diff +29 -0
  61. data/examples/ruby-2.0.0-p0/install/core/diffs/string.c.diff +73 -0
  62. data/examples/ruby-2.0.0-p0/install/core/diffs/struct.c.diff +20 -0
  63. data/examples/ruby-2.0.0-p0/install/core/diffs/time.c.diff +691 -0
  64. data/examples/ruby-2.0.0-p0/install/core/diffs/transcode.c.diff +435 -0
  65. data/examples/ruby-2.0.0-p0/install/core/diffs/variable.c.diff +62 -0
  66. data/examples/ruby-2.0.0-p0/install/core/diffs/vm_backtrace.c.diff +164 -0
  67. data/examples/ruby-2.0.0-p0/install/core/diffs/vm_eval.c.diff +99 -0
  68. data/examples/ruby-2.0.0-p0/install/core/diffs/vm_method.c.diff +17 -0
  69. data/examples/ruby-2.0.0-p0/install/core/diffs/vm_trace.c.diff +393 -0
  70. data/examples/ruby-2.0.0-p0/install/stdlib/.rdx +6 -0
  71. data/examples/ruby-2.0.0-p0/install/stdlib/README +19 -0
  72. data/examples/ruby-2.0.0-p0/install/stdlib/Rakefile +53 -0
  73. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/abbrev.rb.diff +77 -0
  74. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/base64.rb.diff +42 -0
  75. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/benchmark.rb.diff +144 -0
  76. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/cmath.rb.diff +52 -0
  77. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/forwardable.rb.diff +150 -0
  78. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/mathn.rb.diff +58 -0
  79. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/matrix.rb.diff +657 -0
  80. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/observer.rb.diff +31 -0
  81. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/optparse.rb.diff +147 -0
  82. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/ostruct.rb.diff +78 -0
  83. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/prime.rb.diff +52 -0
  84. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/pstore.rb.diff +110 -0
  85. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/scanf.rb.diff +100 -0
  86. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/securerandom.rb.diff +144 -0
  87. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/set.rb.diff +637 -0
  88. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/shellwords.rb.diff +66 -0
  89. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/singleton.rb.diff +37 -0
  90. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/tempfile.rb.diff +104 -0
  91. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/thread.rb.diff +38 -0
  92. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/time.rb.diff +140 -0
  93. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/tmpdir.rb.diff +52 -0
  94. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/uri.rb.diff +39 -0
  95. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/uri/common.rb.diff +237 -0
  96. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/weakref.rb.diff +36 -0
  97. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/yaml/store.rb.diff +27 -0
  98. data/examples/ruby-2.0.0-p0/rakefile +165 -0
  99. data/lib/rdx.rb +331 -0
  100. data/lib/rdx/assertions.rb +484 -0
  101. data/lib/rdx/binding.rb +151 -0
  102. data/lib/rdx/code_object.rb +598 -0
  103. data/lib/rdx/comment.rb +338 -0
  104. data/lib/rdx/convention.rb +1174 -0
  105. data/lib/rdx/directive.rb +1432 -0
  106. data/lib/rdx/example.rb +679 -0
  107. data/lib/rdx/generator.rb +112 -0
  108. data/lib/rdx/generator/rdoc.rb +1006 -0
  109. data/lib/rdx/options.rb +359 -0
  110. data/lib/rdx/plain_text.rb +65 -0
  111. data/lib/rdx/reporter.rb +421 -0
  112. data/lib/rdx/ruby_lex.rb +324 -0
  113. data/lib/rdx/runner.rb +309 -0
  114. data/lib/rdx/source_file.rb +94 -0
  115. data/lib/rdx/specification.rb +194 -0
  116. data/lib/rdx/statement.rb +248 -0
  117. data/lib/rdx/store.rb +119 -0
  118. data/lib/rdx/task.rb +361 -0
  119. data/lib/rdx/text.rb +688 -0
  120. data/lib/rdx/version.rb +15 -0
  121. data/rakefile +64 -0
  122. metadata +203 -0
@@ -0,0 +1,130 @@
1
+ --- core/orig/doc/syntax/calling_methods.rdoc 2015-06-11 07:51:44 +0000
2
+ +++ core/patched/doc/syntax/calling_methods.rdoc 2015-06-28 11:43:44 +0000
3
+ @@ -1,4 +1,5 @@
4
+ = Calling Methods
5
+ +:rdx: off
6
+
7
+ Calling a method sends a message to an object so it can perform some work.
8
+
9
+ @@ -77,12 +78,13 @@
10
+
11
+ If the method definition doesn't include keyword arguments the keyword or
12
+ hash-type arguments are assigned as a single hash to the last argument:
13
+ +:rdx: on
14
+
15
+ def my_method(options)
16
+ p options
17
+ end
18
+
19
+ - my_method('a' => 1, b: 2) # prints: {'a'=>1, :b=>2}
20
+ + my_method('a' => 1, b: 2) # prints: {"a"=>1, :b=>2}
21
+
22
+ If too many positional arguments are given an ArgumentError is raised.
23
+
24
+ @@ -101,15 +103,11 @@
25
+ Here +c+ and +d+ have default values which ruby will apply for you. If you
26
+ send only two arguments to this method:
27
+
28
+ - my_method(1, 2)
29
+ -
30
+ -You will see ruby print <code>[1, 2, 3, 4]</code>.
31
+ + my_method(1, 2) # prints [1, 2, 3, 4]
32
+
33
+ If you send three arguments:
34
+
35
+ - my_method(1, 2, 5)
36
+ -
37
+ -You will see ruby print <code>[1, 2, 5, 4]</code>
38
+ + my_method(1, 2, 5) # prints [1, 2, 5, 4]
39
+
40
+ Ruby fills in the missing arguments from left to right.
41
+
42
+ @@ -123,15 +121,11 @@
43
+ Here +b+ and +c+ have default values. If you send only two arguments to this
44
+ method:
45
+
46
+ - my_method(1, 4)
47
+ -
48
+ -You will see ruby print <code>[1, 2, 3, 4]</code>.
49
+ + my_method(1, 4) # prints [1, 2, 3, 4]
50
+
51
+ If you send three arguments:
52
+
53
+ - my_method(1, 5, 6)
54
+ -
55
+ -You will see ruby print <code>[1, 5, 3, 6]</code>.
56
+ + my_method(1, 5, 6) # prints [1, 5, 3, 6]
57
+
58
+ Describing this in words gets complicated and confusing. I'll describe it
59
+ in variables and values instead.
60
+ @@ -142,6 +136,7 @@
61
+ +c+ uses its default value of <code>3</code>.
62
+
63
+ === Keyword Arguments
64
+ +:rdx: off
65
+
66
+ Keyword arguments follow any positional arguments and are separated by commas
67
+ like positional arguments:
68
+ @@ -194,6 +189,7 @@
69
+ end
70
+
71
+ ==== Block Local Arguments
72
+ +:rdx: on
73
+
74
+ You may also declare block-local arguments to a block using <code>;</code> in
75
+ the block arguments list. Assigning to a block-local argument will not
76
+ @@ -212,17 +208,26 @@
77
+
78
+ puts "place is: #{place}"
79
+
80
+ -This prints:
81
+ +Produces:
82
+
83
+ hello main this is block
84
+ - place is world
85
+ + place is: world
86
+
87
+ So the +place+ variable in the block is not the same +place+ variable as
88
+ outside the block. Removing <code>; place</code> from the block arguments
89
+ gives this result:
90
+ +-- rdx
91
+ + place = "world"
92
+ + my_method do |obj|
93
+ + place = "block"
94
+ + puts "hello #{obj} this is #{place}"
95
+ + end
96
+ + puts "place is: #{place}"
97
+ +:rdx: output
98
+ +++
99
+
100
+ hello main this is block
101
+ - place is block
102
+ + place is: block
103
+
104
+ === Array to Arguments Conversion
105
+
106
+ @@ -288,13 +293,14 @@
107
+ If the method definition uses <code>**</code> to gather arbitrary keyword
108
+ arguments they will not be gathered by <code>*</code>:
109
+
110
+ +:rdx: bug on x64-mingw32 (but not on i386-mingw32) "3"=>4 is not captured by keywords
111
+ def my_method(*a, **kw)
112
+ p arguments: a, keywords: kw
113
+ end
114
+
115
+ my_method(1, 2, '3' => 4, five: 6)
116
+
117
+ -Prints:
118
+ +Produces:
119
+
120
+ {:arguments=>[1, 2], :keywords=>{"3"=>4, :five=>6}}
121
+
122
+ @@ -314,7 +320,7 @@
123
+
124
+ argument = proc { |a| puts "#{a.inspect} was yielded" }
125
+
126
+ - my_method(&argument)
127
+ + my_method(&argument) # prints: main was yielded
128
+
129
+ If the splat operator comes first in the call, parenthesis must be used to
130
+ avoid a warning.
@@ -0,0 +1,254 @@
1
+ --- core/orig/doc/syntax/control_expressions.rdoc 2015-06-11 07:51:44 +0000
2
+ +++ core/patched/doc/syntax/control_expressions.rdoc 2015-06-25 13:32:24 +0000
3
+ @@ -19,13 +19,17 @@
4
+ puts "the test resulted in a true-value"
5
+ end
6
+
7
+ -This will print "the test resulted in a true-value".
8
+ +Produces
9
+ +
10
+ + the test resulted in a true-value
11
+
12
+ The +then+ is optional:
13
+
14
+ +:rdx: off
15
+ if true
16
+ puts "the test resulted in a true-value"
17
+ end
18
+ +:rdx: on
19
+
20
+ This document will omit the optional +then+ for all expressions as that is the
21
+ most common usage of +if+.
22
+ @@ -39,7 +43,8 @@
23
+ puts "the test resulted in a false-value"
24
+ end
25
+
26
+ -This will print "the test resulted in a false-value".
27
+ +Produces
28
+ + the test resulted in a false-value
29
+
30
+ You may add an arbitrary number of extra tests to an if expression using
31
+ +elsif+. An +elsif+ executes when all tests above the +elsif+ are false.
32
+ @@ -54,15 +59,17 @@
33
+ puts "a is some other value"
34
+ end
35
+
36
+ -This will print "a is one" as <code>1</code> is not equal to <code>0</code>.
37
+ -Since +else+ is only executed when there are no matching conditions.
38
+ +Produces:
39
+
40
+ -Once a condition matches, either the +if+ condition or any +elsif+ condition,
41
+ -the +if+ expression is complete and no further tests will be performed.
42
+ + a is one
43
+ +
44
+ +as <code>1</code> is not equal to <code>0</code>.
45
+ +Since +else+ is only executed when there are no matching conditions.
46
+
47
+ Like an +if+, an +elsif+ condition may be followed by a +then+.
48
+
49
+ -In this example only "a is one" is printed:
50
+ +Once a condition matches, either the +if+ condition or any +elsif+ condition,
51
+ +the +if+ expression is complete and no further tests will be performed:
52
+
53
+ a = 1
54
+
55
+ @@ -76,9 +83,15 @@
56
+ puts "a is some other value"
57
+ end
58
+
59
+ +Produces
60
+ +
61
+ + a is one
62
+ +
63
+ The tests for +if+ and +elsif+ may have side-effects. The most common use of
64
+ side-effect is to cache a value into a local variable:
65
+
66
+ +:rdx: off
67
+ +
68
+ if a = object.some_value
69
+ # do something to a
70
+ end
71
+ @@ -108,6 +121,7 @@
72
+ expression as this can be confusing.
73
+
74
+ == +unless+ Expression
75
+ +:rdx: on
76
+
77
+ The +unless+ expression is the opposite of the +if+ expression. If the value
78
+ is false the "then" expression is executed:
79
+ @@ -134,7 +148,11 @@
80
+ puts "the value is true"
81
+ end
82
+
83
+ -This prints "the value is true" from the +else+ condition.
84
+ +Produces
85
+ +
86
+ + the value is true
87
+ +
88
+ +from the +else+ condition.
89
+
90
+ You may not use +elsif+ with an +unless+ expression.
91
+
92
+ @@ -148,28 +166,23 @@
93
+ is the "test" expression:
94
+
95
+ a = 0
96
+ -
97
+ a += 1 if a.zero?
98
+ -
99
+ - p a
100
+ -
101
+ -This will print 1.
102
+ + p a # prints 1
103
+
104
+ a = 0
105
+ -
106
+ a += 1 unless a.zero?
107
+ -
108
+ - p a
109
+ -
110
+ -This will print 0.
111
+ + p a # prints 0
112
+
113
+ While the modifier and standard versions have both a "test" expression and a
114
+ "then" expression, they are not exact transformations of each other due to
115
+ parse order. Here is an example that shows the difference:
116
+ +:rdx: new_binding
117
+
118
+ p a if a = 0.zero?
119
+
120
+ -This raises the NameError "undefined local variable or method `a'".
121
+ +raises
122
+ +
123
+ + undefined local variable or method `a' (NameError)
124
+
125
+ When ruby parses this expression it first encounters +a+ as a method call in
126
+ the "then" expression, then later it sees the assignment to +a+ in the "test"
127
+ @@ -197,9 +210,9 @@
128
+
129
+ case "12345"
130
+ when /^1/
131
+ - puts "the string starts with one"
132
+ + # the string starts with one
133
+ else
134
+ - puts "I don't know what the string starts with"
135
+ + # I don't know what the string starts with
136
+ end
137
+
138
+ Here the string <code>"12345"</code> is compared with <code>/^1/</code> by
139
+ @@ -214,14 +227,14 @@
140
+
141
+ case "12345"
142
+ when /^1/
143
+ - puts "the string starts with one"
144
+ + # the string starts with one
145
+ end
146
+
147
+ You may place multiple conditions on the same +when+:
148
+
149
+ case "2"
150
+ when /^1/, "2"
151
+ - puts "the string starts with one or is '2'"
152
+ + # the string starts with one or is '2'
153
+ end
154
+
155
+ Ruby will try each condition in turn, so first <code>/^1/ === "2"</code>
156
+ @@ -231,23 +244,26 @@
157
+ You may use +then+ after the +when+ condition. This is most frequently used
158
+ to place the body of the +when+ on a single line.
159
+
160
+ +:rdx: off
161
+ case a
162
+ - when 1, 2 then puts "a is one or two
163
+ + when 1, 2 then puts "a is one or two"
164
+ when 3 then puts "a is three"
165
+ else puts "I don't know what a is"
166
+ end
167
+
168
+ +
169
+ The other way to use a +case+ expression is like an if-elsif expression:
170
+ +:rdx: on
171
+
172
+ a = 2
173
+
174
+ case
175
+ when a == 1, a == 2
176
+ - puts "a is one or two"
177
+ + # a is one or two
178
+ when a == 3
179
+ - puts "a is three"
180
+ + # a is three
181
+ else
182
+ - puts "I don't know what a is"
183
+ + # I don't know what a is
184
+ end
185
+
186
+ Again, the +then+ and +else+ are optional.
187
+ @@ -256,6 +272,7 @@
188
+ expression.
189
+
190
+ == +while+ Loop
191
+ +:rdx: off
192
+
193
+ The +while+ loop executes while a condition is true:
194
+
195
+ @@ -306,6 +323,7 @@
196
+ used.
197
+
198
+ == +for+ Loop
199
+ +:rdx: on
200
+
201
+ The +for+ loop consists of +for+ followed by a variable to contain the
202
+ iteration argument followed by +in+ and the value to iterate over using #each.
203
+ @@ -315,7 +333,11 @@
204
+ puts value
205
+ end
206
+
207
+ -Prints 1, 2 and 3.
208
+ +Produces
209
+ +
210
+ + 1
211
+ + 2
212
+ + 3
213
+
214
+ Like +while+ and +until+, the +do+ is optional.
215
+
216
+ @@ -360,6 +382,7 @@
217
+ handling overhead.
218
+
219
+ == +break+ Statement
220
+ +:rdx: off
221
+
222
+ Use +break+ to leave a block early. This will stop iterating over the items in +values+ if one of them is even:
223
+
224
+ @@ -370,6 +393,7 @@
225
+ end
226
+
227
+ You can also terminate from a +while+ loop using +break+:
228
+ +:rdx: on
229
+
230
+ a = 0
231
+
232
+ @@ -382,7 +406,10 @@
233
+
234
+ p a
235
+
236
+ -This prints the numbers 0 and 1.
237
+ +Produces
238
+ +
239
+ + 0
240
+ + 1
241
+
242
+ +break+ accepts a value that supplies the result of the expression it is
243
+ "breaking" out of:
244
+ @@ -430,9 +457,7 @@
245
+ result << result.length + 1
246
+ end
247
+
248
+ - p result
249
+ -
250
+ -This prints [0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11]
251
+ + p result # prints [0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11]
252
+
253
+ In Ruby 1.8 you could also use +retry+ where you used +redo+. This is no
254
+ longer true, now you will receive a SyntaxError when you use +retry+ outside
@@ -0,0 +1,54 @@
1
+ --- core/orig/doc/syntax/literals.rdoc 2015-06-11 07:51:44 +0000
2
+ +++ core/patched/doc/syntax/literals.rdoc 2015-06-25 17:35:23 +0000
3
+ @@ -89,7 +89,7 @@
4
+ Double-quote strings allow interpolation of other values using
5
+ <tt>#{...}</tt>:
6
+
7
+ - "One plus one is two: #{1 + 1}"
8
+ + "One plus one is two: #{1 + 1}" #=> "One plus one is two: 2"
9
+
10
+ Any expression may be placed inside the interpolated section, but it's best to
11
+ keep the expression small for readability.
12
+ @@ -149,15 +149,18 @@
13
+ One plus one is #{1 + 1}
14
+ EXPECTED
15
+
16
+ - p expected_result # prints: "One plus one is \#{1 + 1}\n"
17
+ + expected_result # => "One plus one is \#{1 + 1}\n"
18
+
19
+ The identifier may also be surrounded with double quotes (which is the same as
20
+ no quotes) or with backticks. When surrounded by backticks the HEREDOC
21
+ behaves like Kernel#`:
22
+
23
+ - puts <<-`HEREDOC`
24
+ - cat #{__FILE__}
25
+ +:rdx: off -
26
+ + heredoc = <<-`HEREDOC`
27
+ + cat "#{__FILE__}"
28
+ HEREDOC
29
+ + # If the shell command cat is available:
30
+ + # heredoc == File.read(__FILE__)
31
+
32
+ To call a method on a heredoc place it after the opening identifier:
33
+
34
+ @@ -174,6 +177,11 @@
35
+ content for heredoc two
36
+ TWO
37
+
38
+ +produces
39
+ +
40
+ + content for heredoc one
41
+ + content for heredoc two
42
+ +
43
+ == Symbols
44
+
45
+ A Symbol represents a name inside the ruby interpreter. See Symbol for more
46
+ @@ -191,7 +199,7 @@
47
+
48
+ Like strings, a single-quote may be used to disable interpolation:
49
+
50
+ - :"my_symbol#{1 + 1}" #=> :"my_symbol\#{1 + 1}"
51
+ + :'my_symbol#{1 + 1}' #=> :"my_symbol\#{1 + 1}"
52
+
53
+ When creating a Hash there is a special syntax for referencing a Symbol as
54
+ well.
@@ -0,0 +1,157 @@
1
+ --- core/orig/doc/syntax/methods.rdoc 2015-06-11 07:51:44 +0000
2
+ +++ core/patched/doc/syntax/methods.rdoc 2015-06-19 07:38:11 +0000
3
+ @@ -82,7 +82,7 @@
4
+
5
+ obj = C.new
6
+
7
+ - -obj # prints "you inverted this object"
8
+ + -obj # prints: you inverted this object
9
+
10
+ Unary methods accept zero arguments.
11
+
12
+ @@ -152,13 +152,16 @@
13
+ self + ", world!"
14
+ end
15
+
16
+ - greeting.broaden # returns "Hello, world!"
17
+ + greeting.broaden # => "Hello, world!"
18
+
19
+ +self+ is a keyword referring to the current object under consideration
20
+ by the compiler, which might make the use of +self+ in defining a class
21
+ method above a little clearer. Indeed, the example of adding a +hello+
22
+ method to the class +String+ can be rewritten thus:
23
+
24
+ +-- rdx
25
+ + String = 'Not true ::String'
26
+ +++
27
+ def String.hello
28
+ "Hello, world!"
29
+ end
30
+ @@ -172,23 +175,32 @@
31
+ method already exists: it simply redefines it. This is called
32
+ _overriding_. Rather like extending core classes, this is a potentially
33
+ dangerous ability, and should be used sparingly because it can cause unexpected
34
+ -results. For example, consider this irb session:
35
+ +results. For example, consider the following:
36
+
37
+ - >> "43".to_i
38
+ - => 43
39
+ - >> class String
40
+ - >> def to_i
41
+ - >> 42
42
+ - >> end
43
+ - >> end
44
+ - => nil
45
+ - >> "43".to_i
46
+ - => 42
47
+ +:rdx: toplevel
48
+ +
49
+ + "43".to_i #=> 43
50
+ + class String
51
+ +-- rdx
52
+ + alias rdx_doc_methods_to_i to_i
53
+ +++
54
+ + def to_i
55
+ + 42
56
+ + end
57
+ + end
58
+ + "43".to_i #=> 42
59
+ +-- rdx
60
+ + class String
61
+ + alias to_i rdx_doc_methods_to_i
62
+ + remove_method :rdx_doc_methods_to_i
63
+ + end
64
+ +++
65
+
66
+ This will effectively sabotage any code which makes use of the method
67
+ <code>String#to_i</code> to parse numbers from strings.
68
+
69
+ == Arguments
70
+ +:rdx: new_binding
71
+
72
+ A method may accept arguments. The argument list follows the method name:
73
+
74
+ @@ -231,12 +243,15 @@
75
+ a + b + c
76
+ end
77
+
78
+ -This will raise a SyntaxError:
79
+ +But this
80
+
81
+ def add_values(a = 1, b, c = 1)
82
+ a + b + c
83
+ end
84
+
85
+ +will raise a SyntaxError.
86
+ +:rdx: error SyntaxError
87
+ +
88
+ === Array Decomposition
89
+
90
+ You can decompose (unpack or extract values from) an Array using extra
91
+ @@ -248,7 +263,7 @@
92
+
93
+ my_method([1, 2])
94
+
95
+ -This prints:
96
+ +produces
97
+
98
+ {:a=>1, :b=>2}
99
+
100
+ @@ -260,6 +275,8 @@
101
+
102
+ my_method([1, 2, 3])
103
+
104
+ +:rdx: output {:a=>1, :b=>2}
105
+ +
106
+ This has the same output as above.
107
+
108
+ You can use a <code>*</code> to collect the remaining arguments. This splits
109
+ @@ -271,7 +288,7 @@
110
+
111
+ my_method([1, 2, 3])
112
+
113
+ -This prints:
114
+ +produces
115
+
116
+ {:a=>1, :b=>[2, 3]}
117
+
118
+ @@ -288,7 +305,7 @@
119
+
120
+ my_method(1, 2, 3)
121
+
122
+ -This prints:
123
+ +produces
124
+
125
+ {:a=>1, :b=>2, :c=>nil, :d=>3}
126
+
127
+ @@ -324,7 +341,7 @@
128
+ end
129
+
130
+ gather_arguments_keyword 1, 2, three: 3
131
+ - #=> raises: unknown keyword: three (ArgumentError)
132
+ + # raises ArgumentError: unknown keyword: three
133
+
134
+ Also, note that a bare <code>*</code> can be used to ignore arguments:
135
+
136
+ @@ -346,7 +363,11 @@
137
+ end
138
+
139
+ gather_arguments first: 1, second: 2, third: 3
140
+ - # prints 1 then {:second=>2, :third=>3}
141
+ +
142
+ +produces
143
+ +
144
+ + 1
145
+ + {:second=>2, :third=>3}
146
+
147
+ When calling a method with keyword arguments the arguments may appear in any
148
+ order. If an unknown keyword argument is sent by the caller an ArgumentError
149
+ @@ -360,7 +381,7 @@
150
+ The block argument is indicated by <code>&</code> and must come last:
151
+
152
+ def my_method(&my_block)
153
+ - my_method.call(self)
154
+ + my_block.call(self)
155
+ end
156
+
157
+ Most frequently the block argument is used to pass a block to another method: