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,91 @@
|
|
1
|
+
--- core/orig/doc/syntax/miscellaneous.rdoc 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/doc/syntax/miscellaneous.rdoc 2015-06-19 07:39:39 +0000
|
3
|
+
@@ -21,6 +21,9 @@
|
4
|
+
The +alias+ keyword is most frequently used to alias methods. When aliasing a
|
5
|
+
method you can use either its name or a symbol:
|
6
|
+
|
7
|
+
+-- rdx
|
8
|
+
+ def old_name; end
|
9
|
+
+++
|
10
|
+
alias new_name old_name
|
11
|
+
alias :new_name :old_name
|
12
|
+
|
13
|
+
@@ -33,6 +36,9 @@
|
14
|
+
alias $new $old
|
15
|
+
|
16
|
+
p $new # prints 0
|
17
|
+
+-- rdx
|
18
|
+
+ $old = $new = nil
|
19
|
+
+++
|
20
|
+
|
21
|
+
You may use +alias+ in any scope.
|
22
|
+
|
23
|
+
@@ -41,13 +47,22 @@
|
24
|
+
The +undef+ keyword prevents the current class from responding to calls to the
|
25
|
+
named methods.
|
26
|
+
|
27
|
+
+-- rdx
|
28
|
+
+ def my_method; end
|
29
|
+
+++
|
30
|
+
undef my_method
|
31
|
+
|
32
|
+
You may use symbols instead of method names:
|
33
|
+
|
34
|
+
+-- rdx
|
35
|
+
+ def my_method; end
|
36
|
+
+++
|
37
|
+
undef :my_method
|
38
|
+
|
39
|
+
You may undef multiple methods:
|
40
|
+
+-- rdx
|
41
|
+
+ def method1; end; alias method2 method1
|
42
|
+
+++
|
43
|
+
|
44
|
+
undef method1, method2
|
45
|
+
|
46
|
+
@@ -68,12 +83,14 @@
|
47
|
+
instance variable is zero:
|
48
|
+
|
49
|
+
defined? @instance_variable && @instance_variable.zero?
|
50
|
+
+ # => "expression"
|
51
|
+
|
52
|
+
-This returns <code>"expression"</code> which is not what you want if the
|
53
|
+
+This result is not what you want if the
|
54
|
+
instance variable is not defined.
|
55
|
+
|
56
|
+
@instance_variable = 1
|
57
|
+
defined?(@instance_variable) && @instance_variable.zero?
|
58
|
+
+ # => false
|
59
|
+
|
60
|
+
Adding parentheses when checking if the instance variable is defined is a
|
61
|
+
better check. This correctly returns +nil+ when the instance variable is not
|
62
|
+
@@ -94,14 +111,26 @@
|
63
|
+
|
64
|
+
Here is an example:
|
65
|
+
|
66
|
+
+:rdx: off
|
67
|
+
+
|
68
|
+
BEGIN {
|
69
|
+
count = 0
|
70
|
+
}
|
71
|
+
|
72
|
+
You must use <code>{</code> and <code>}</code> you may not use +do+ and +end+.
|
73
|
+
|
74
|
+
-Here is an example one-liner that adds numbers from standard input or any files
|
75
|
+
-in the argument list:
|
76
|
+
+Follows an example that adds numbers from standard input or any files
|
77
|
+
+in the argument list. So having the file:
|
78
|
+
+
|
79
|
+
+:rdx: on
|
80
|
+
+
|
81
|
+
+ # File: number_list
|
82
|
+
+ 2
|
83
|
+
+ 4
|
84
|
+
+ -5
|
85
|
+
+ 3
|
86
|
+
|
87
|
+
- ruby -ne 'BEGIN { count = 0 }; END { puts count }; count += gets.to_i'
|
88
|
+
+the one-liner command is
|
89
|
+
|
90
|
+
+ $ ruby -ne 'BEGIN { count = 0 }; END { puts count }; count += $_.to_i' number_list
|
91
|
+
+ 4
|
@@ -0,0 +1,161 @@
|
|
1
|
+
--- core/orig/doc/syntax/modules_and_classes.rdoc 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/doc/syntax/modules_and_classes.rdoc 2015-06-19 08:02:30 +0000
|
3
|
+
@@ -84,15 +84,26 @@
|
4
|
+
the constant <code>A::Z</code> is accessible from B as A is part of the
|
5
|
+
nesting:
|
6
|
+
|
7
|
+
+:rdx: toplevel
|
8
|
+
+
|
9
|
+
module A
|
10
|
+
Z = 1
|
11
|
+
|
12
|
+
module B
|
13
|
+
- p Module.nesting #=> [A::B, A]
|
14
|
+
- p Z #=> 1
|
15
|
+
+ p Module.nesting
|
16
|
+
+ p Z
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
+-- rdx
|
21
|
+
+ Object.send :remove_const, :A
|
22
|
+
+++
|
23
|
+
+
|
24
|
+
+produces
|
25
|
+
+
|
26
|
+
+ [A::B, A]
|
27
|
+
+ 1
|
28
|
+
+
|
29
|
+
However, if you use <code>::</code> to define <code>A::B</code> without
|
30
|
+
nesting it inside +A+ a NameError exception will be raised because the nesting
|
31
|
+
does not include +A+:
|
32
|
+
@@ -102,24 +113,47 @@
|
33
|
+
end
|
34
|
+
|
35
|
+
module A::B
|
36
|
+
- p Module.nesting #=> [A::B]
|
37
|
+
- p Z #=> raises NameError
|
38
|
+
+ p Module.nesting
|
39
|
+
+ p Z
|
40
|
+
end
|
41
|
+
|
42
|
+
+produces
|
43
|
+
+:rdx: error NameError
|
44
|
+
+
|
45
|
+
+ [A::B]
|
46
|
+
+
|
47
|
+
+(then raises the exception)
|
48
|
+
+
|
49
|
+
+-- rdx
|
50
|
+
+ Object.send :remove_const, :A
|
51
|
+
+++
|
52
|
+
+
|
53
|
+
If a constant is defined at the top-level you may preceded it with
|
54
|
+
<code>::</code> to reference it:
|
55
|
+
|
56
|
+
+:rdx: toplevel
|
57
|
+
+
|
58
|
+
Z = 0
|
59
|
+
|
60
|
+
module A
|
61
|
+
Z = 1
|
62
|
+
|
63
|
+
module B
|
64
|
+
- p ::Z #=> 0
|
65
|
+
+ p ::Z
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
+-- rdx
|
70
|
+
+ Object.send :remove_const, :Z
|
71
|
+
+ Object.send :remove_const, :A
|
72
|
+
+++
|
73
|
+
+
|
74
|
+
+produces
|
75
|
+
+
|
76
|
+
+ 0
|
77
|
+
+
|
78
|
+
=== Methods
|
79
|
+
+:rdx: new_binding
|
80
|
+
|
81
|
+
For method definition documentation see the {syntax documentation for
|
82
|
+
methods}[rdoc-ref:syntax/methods.rdoc].
|
83
|
+
@@ -146,8 +180,8 @@
|
84
|
+
|
85
|
+
include A
|
86
|
+
|
87
|
+
- p self.class.ancestors #=> [Object, A, Kernel, BasicObject]
|
88
|
+
- p z #=> 1
|
89
|
+
+ self.is_a? A #=> true
|
90
|
+
+ z #=> 1
|
91
|
+
|
92
|
+
=== Visibility
|
93
|
+
|
94
|
+
@@ -163,6 +197,7 @@
|
95
|
+
state to any caller and would like to restrict it only to inherited classes.
|
96
|
+
|
97
|
+
Here is an example:
|
98
|
+
+:rdx: new_binding
|
99
|
+
|
100
|
+
class A
|
101
|
+
def n(other)
|
102
|
+
@@ -186,9 +221,9 @@
|
103
|
+
b = B.new
|
104
|
+
c = C.new
|
105
|
+
|
106
|
+
- c.n b #=> 1 -- C is a subclass of B
|
107
|
+
- b.n b #=> 1 -- m called on defining class
|
108
|
+
- a.n b # raises NoMethodError A is not a subclass of B
|
109
|
+
+ c.n b #=> 1 # C is a subclass of B
|
110
|
+
+ b.n b #=> 1 # m called on defining class
|
111
|
+
+ a.n b # raises NoMethodError # A is not a subclass of B
|
112
|
+
|
113
|
+
The third visibility is +private+. A private method may not be called with a
|
114
|
+
receiver, not even +self+. If a private method is called with a receiver a
|
115
|
+
@@ -201,6 +236,7 @@
|
116
|
+
section}[rdoc-ref:syntax/miscellaneous.rdoc] for documentation.
|
117
|
+
|
118
|
+
= Classes
|
119
|
+
+:rdx: new_binding
|
120
|
+
|
121
|
+
Every class is also a module, but unlike modules a class may not be mixed-in to
|
122
|
+
another module (or class). Like a module, a class can be used as a namespace.
|
123
|
+
@@ -242,9 +278,10 @@
|
124
|
+
class B < A
|
125
|
+
end
|
126
|
+
|
127
|
+
- p B.new.z #=> 1
|
128
|
+
+ B.new.z #=> 1
|
129
|
+
|
130
|
+
The same is true for constants:
|
131
|
+
+:rdx: new_binding
|
132
|
+
|
133
|
+
class A
|
134
|
+
Z = 1
|
135
|
+
@@ -256,7 +293,7 @@
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
- p B.new.z #=> 1
|
140
|
+
+ B.new.z #=> 1
|
141
|
+
|
142
|
+
You can override the functionality of a superclass method by redefining the
|
143
|
+
method:
|
144
|
+
@@ -273,7 +310,7 @@
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
- p B.new.m #=> 2
|
149
|
+
+ B.new.m #=> 2
|
150
|
+
|
151
|
+
If you wish to invoke the superclass functionality from a method use +super+:
|
152
|
+
|
153
|
+
@@ -289,7 +326,7 @@
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
- p B.new.m #=> 3
|
158
|
+
+ B.new.m #=> 3
|
159
|
+
|
160
|
+
When used without any arguments +super+ uses the arguments given to the
|
161
|
+
subclass method. To send no arguments to the superclass method use
|
@@ -0,0 +1,8 @@
|
|
1
|
+
--- core/orig/doc/syntax/precedence.rdoc 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/doc/syntax/precedence.rdoc 2015-06-19 07:43:40 +0000
|
3
|
+
@@ -1,4 +1,5 @@
|
4
|
+
= Precedence
|
5
|
+
+:rdx: off
|
6
|
+
|
7
|
+
From highest to lowest, this is the precedence table for ruby. High precedence
|
8
|
+
operations happen before low precedence operations.
|
@@ -0,0 +1,146 @@
|
|
1
|
+
--- core/orig/doc/syntax/refinements.rdoc 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/doc/syntax/refinements.rdoc 2015-06-19 07:46:50 +0000
|
3
|
+
@@ -11,14 +11,14 @@
|
4
|
+
|
5
|
+
Refinements are an experimental feature in Ruby 2.0. At the time of writing,
|
6
|
+
refinements are expected to exist in future versions of Ruby but the
|
7
|
+
-specification of refinements may change. You will receive a warning the first
|
8
|
+
-time you define or activate a refinement.
|
9
|
+
+specification of refinements may change.
|
10
|
+
|
11
|
+
Here is a basic refinement:
|
12
|
+
+:rdx: toplevel
|
13
|
+
|
14
|
+
class C
|
15
|
+
def foo
|
16
|
+
- puts "C#foo
|
17
|
+
+ puts "C#foo"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
@@ -30,6 +30,11 @@
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
+You will receive a warning the first time you define or activate a refinement:
|
26
|
+
+:rdx: stderr
|
27
|
+
+
|
28
|
+
+ warning: Refinements are experimental, and the behavior may change in future versions of Ruby!
|
29
|
+
+
|
30
|
+
First, a class +C+ is defined. Next a refinement for +C+ is created using
|
31
|
+
Module#refine. Refinements only modify classes, not modules so the argument
|
32
|
+
must be a class.
|
33
|
+
@@ -42,9 +47,14 @@
|
34
|
+
|
35
|
+
using M
|
36
|
+
|
37
|
+
- x = C.new
|
38
|
+
+ c = C.new
|
39
|
+
|
40
|
+
- c.foo # prints "C#foo in M"
|
41
|
+
+ c.foo # prints: C#foo in M
|
42
|
+
+
|
43
|
+
+-- rdx
|
44
|
+
+ Object.send :remove_const, :C
|
45
|
+
+ Object.send :remove_const, :M
|
46
|
+
+++
|
47
|
+
|
48
|
+
== Scope
|
49
|
+
|
50
|
+
@@ -75,20 +85,25 @@
|
51
|
+
using M
|
52
|
+
|
53
|
+
x = C.new
|
54
|
+
- x.foo # prints "C#foo in M"
|
55
|
+
- call_foo(x) #=> raises NoMethodError
|
56
|
+
+ x.foo # prints: C#foo in M
|
57
|
+
+ call_foo(x) # raises NoMethodError
|
58
|
+
+
|
59
|
+
+-- rdx
|
60
|
+
+ Object.send :remove_const, :C
|
61
|
+
+ Object.send :remove_const, :M
|
62
|
+
+ Object.send :remove_method, :call_foo
|
63
|
+
+++
|
64
|
+
|
65
|
+
If a method is defined in a scope where a refinement is active the refinement
|
66
|
+
will be active when the method is called. This example spans multiple files:
|
67
|
+
|
68
|
+
-c.rb:
|
69
|
+
-
|
70
|
+
+ # File: c.rb
|
71
|
+
class C
|
72
|
+
end
|
73
|
+
|
74
|
+
-m.rb:
|
75
|
+
-
|
76
|
+
- require "c"
|
77
|
+
+:rdx: # start a new example, so that implicit directives kicks in again
|
78
|
+
+ # File: m.rb
|
79
|
+
+ load File.expand_path 'c.rb'
|
80
|
+
|
81
|
+
module M
|
82
|
+
refine C do
|
83
|
+
@@ -98,9 +113,9 @@
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
-m_user.rb:
|
88
|
+
-
|
89
|
+
- require "m"
|
90
|
+
+:rdx:
|
91
|
+
+ # File: m_user.rb
|
92
|
+
+ load File.expand_path 'm.rb'
|
93
|
+
|
94
|
+
using M
|
95
|
+
|
96
|
+
@@ -110,14 +125,20 @@
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
-main.rb:
|
101
|
+
-
|
102
|
+
- require "m_user"
|
103
|
+
+:rdx:
|
104
|
+
+ # in main:
|
105
|
+
+ load File.expand_path 'm_user.rb'
|
106
|
+
|
107
|
+
x = C.new
|
108
|
+
m_user = MUser.new
|
109
|
+
- m_user.call_foo(x) # prints "C#foo in M"
|
110
|
+
- x.foo #=> raises NoMethodError
|
111
|
+
+ m_user.call_foo(x) # prints: C#foo in M
|
112
|
+
+ x.foo # raises NoMethodError
|
113
|
+
+
|
114
|
+
+-- rdx
|
115
|
+
+ Object.send :remove_const, :C
|
116
|
+
+ Object.send :remove_const, :M
|
117
|
+
+ Object.send :remove_const, :MUser
|
118
|
+
+++
|
119
|
+
|
120
|
+
Since the refinement +M+ is active in <code>m_user.rb</code> where
|
121
|
+
<code>MUser#call_foo</code> is defined it is also active when
|
122
|
+
@@ -127,6 +148,7 @@
|
123
|
+
are examples of where a refinement +M+ is and is not active.
|
124
|
+
|
125
|
+
In a file:
|
126
|
+
+:rdx: off
|
127
|
+
|
128
|
+
# not activated here
|
129
|
+
using M
|
130
|
+
@@ -161,6 +183,7 @@
|
131
|
+
When defining multiple refinements in the same module, inside a refine block
|
132
|
+
all refinements from the same module are active when a refined method is
|
133
|
+
called:
|
134
|
+
+:rdx: on
|
135
|
+
|
136
|
+
module ToJSON
|
137
|
+
refine Integer do
|
138
|
+
@@ -184,7 +207,7 @@
|
139
|
+
|
140
|
+
using ToJSON
|
141
|
+
|
142
|
+
- p [{1=>2}, {3=>4}].to_json # prints "[{\"1\":2},{\"3\":4}]"
|
143
|
+
+ puts [{1=>2}, {3=>4}].to_json # prints [{"1":2},{"3":4}]
|
144
|
+
|
145
|
+
== Method Lookup
|
146
|
+
|
@@ -0,0 +1,276 @@
|
|
1
|
+
--- core/orig/encoding.c 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/encoding.c 2015-06-28 11:38:56 +0000
|
3
|
+
@@ -1022,7 +1022,7 @@
|
4
|
+
*
|
5
|
+
* Returns the list of name and aliases of the encoding.
|
6
|
+
*
|
7
|
+
- * Encoding::WINDOWS_31J.names #=> ["Windows-31J", "CP932", "csWindows31J"]
|
8
|
+
+ * Encoding::WINDOWS_31J.names #=> ["Windows-31J", "CP932", "csWindows31J", "SJIS", "PCK"]
|
9
|
+
*/
|
10
|
+
static VALUE
|
11
|
+
enc_names(VALUE self)
|
12
|
+
@@ -1042,15 +1042,13 @@
|
13
|
+
* Returns the list of loaded encodings.
|
14
|
+
*
|
15
|
+
* Encoding.list
|
16
|
+
- * #=> [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>,
|
17
|
+
- * #<Encoding:ISO-2022-JP (dummy)>]
|
18
|
+
+ * #-> [Encoding::ASCII_8BIT, Encoding::UTF_8]
|
19
|
+
*
|
20
|
+
* Encoding.find("US-ASCII")
|
21
|
+
- * #=> #<Encoding:US-ASCII>
|
22
|
+
+ * #=> Encoding::US_ASCII
|
23
|
+
*
|
24
|
+
* Encoding.list
|
25
|
+
- * #=> [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>,
|
26
|
+
- * #<Encoding:US-ASCII>, #<Encoding:ISO-2022-JP (dummy)>]
|
27
|
+
+ * #-> [Encoding::ASCII_8BIT, Encoding::UTF_8, Encoding::US_ASCII]
|
28
|
+
*
|
29
|
+
*/
|
30
|
+
static VALUE
|
31
|
+
@@ -1069,8 +1067,9 @@
|
32
|
+
* Search the encoding with specified <i>name</i>.
|
33
|
+
* <i>name</i> should be a string or symbol.
|
34
|
+
*
|
35
|
+
- * Encoding.find("US-ASCII") #=> #<Encoding:US-ASCII>
|
36
|
+
- * Encoding.find(:Shift_JIS) #=> #<Encoding:Shift_JIS>
|
37
|
+
+ * Encoding.find("US-ASCII") #=> Encoding::US_ASCII
|
38
|
+
+ * :rdx: bug symbols aren't accepted
|
39
|
+
+ * Encoding.find(:Shift_JIS) #=> Encoding::Shift_JIS
|
40
|
+
*
|
41
|
+
* Names which this method accept are encoding names and aliases
|
42
|
+
* including following special aliases
|
43
|
+
@@ -1107,7 +1106,7 @@
|
44
|
+
* if they are compatible, nil if they are not.
|
45
|
+
*
|
46
|
+
* Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b")
|
47
|
+
- * #=> #<Encoding:ISO-8859-1>
|
48
|
+
+ * #=> Encoding::ISO_8859_1
|
49
|
+
*
|
50
|
+
* Encoding.compatible?(
|
51
|
+
* "\xa1".force_encoding("iso-8859-1"),
|
52
|
+
@@ -1454,18 +1453,20 @@
|
53
|
+
*
|
54
|
+
* Returns the locale charmap name.
|
55
|
+
* It returns nil if no appropriate information.
|
56
|
+
+ *
|
57
|
+
+ * :rdx: off
|
58
|
+
*
|
59
|
+
- * Debian GNU/Linux
|
60
|
+
- * LANG=C
|
61
|
+
- * Encoding.locale_charmap #=> "ANSI_X3.4-1968"
|
62
|
+
- * LANG=ja_JP.EUC-JP
|
63
|
+
- * Encoding.locale_charmap #=> "EUC-JP"
|
64
|
+
- *
|
65
|
+
- * SunOS 5
|
66
|
+
- * LANG=C
|
67
|
+
- * Encoding.locale_charmap #=> "646"
|
68
|
+
- * LANG=ja
|
69
|
+
- * Encoding.locale_charmap #=> "eucJP"
|
70
|
+
+ * # on Debian GNU/Linux
|
71
|
+
+ * $ LANG=C ruby -e 'puts Encoding.locale_charmap'
|
72
|
+
+ * ANSI_X3.4-1968
|
73
|
+
+ * $ LANG=ja_JP.EUC-JP ruby -e 'puts Encoding.locale_charmap'
|
74
|
+
+ * EUC-JP
|
75
|
+
+ *
|
76
|
+
+ * # on SunOS 5
|
77
|
+
+ * $ LANG=C ruby -e 'puts Encoding.locale_charmap'
|
78
|
+
+ * 646
|
79
|
+
+ * $ LANG=ja_JP.EUC-JP ruby -e 'puts Encoding.locale_charmap'
|
80
|
+
+ * eucJP
|
81
|
+
*
|
82
|
+
* The result is highly platform dependent.
|
83
|
+
* So Encoding.find(Encoding.locale_charmap) may cause an error.
|
84
|
+
@@ -1569,10 +1570,12 @@
|
85
|
+
* Returns the list of available encoding names.
|
86
|
+
*
|
87
|
+
* Encoding.name_list
|
88
|
+
- * #=> ["US-ASCII", "ASCII-8BIT", "UTF-8",
|
89
|
+
- * "ISO-8859-1", "Shift_JIS", "EUC-JP",
|
90
|
+
- * "Windows-31J",
|
91
|
+
- * "BINARY", "CP932", "eucJP"]
|
92
|
+
+ * # -> ["US-ASCII", "ASCII-8BIT", "UTF-8",
|
93
|
+
+ * # "ISO-8859-1", "Shift_JIS", "EUC-JP",
|
94
|
+
+ * # "Windows-31J",
|
95
|
+
+ * # "BINARY", "CP932", "eucJP",
|
96
|
+
+ * # # ...
|
97
|
+
+ * # ]
|
98
|
+
*
|
99
|
+
*/
|
100
|
+
|
101
|
+
@@ -1616,8 +1619,10 @@
|
102
|
+
* Returns the hash of available encoding alias and original encoding name.
|
103
|
+
*
|
104
|
+
* Encoding.aliases
|
105
|
+
- * #=> {"BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-1986"=>"US-ASCII",
|
106
|
+
- * "SJIS"=>"Shift_JIS", "eucJP"=>"EUC-JP", "CP932"=>"Windows-31J"}
|
107
|
+
+ * #-> { "BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-1986"=>"US-ASCII",
|
108
|
+
+ * # "SJIS"=>"Shift_JIS", "eucJP"=>"EUC-JP", "CP932"=>"Windows-31J",
|
109
|
+
+ * # # ...
|
110
|
+
+ * # }
|
111
|
+
*
|
112
|
+
*/
|
113
|
+
|
114
|
+
@@ -1637,7 +1642,7 @@
|
115
|
+
* optionally, aliases:
|
116
|
+
*
|
117
|
+
* Encoding::ISO_8859_1.name
|
118
|
+
- * #=> #<Encoding:ISO-8859-1>
|
119
|
+
+ * #=> "ISO-8859-1"
|
120
|
+
*
|
121
|
+
* Encoding::ISO_8859_1.names
|
122
|
+
* #=> ["ISO-8859-1", "ISO8859-1"]
|
123
|
+
@@ -1647,12 +1652,12 @@
|
124
|
+
* can be passed an Encoding name or alias instead).
|
125
|
+
*
|
126
|
+
* "some string".encoding
|
127
|
+
- * #=> #<Encoding:UTF-8>
|
128
|
+
+ * #=> Encoding::UTF_8
|
129
|
+
*
|
130
|
+
* string = "some string".encode(Encoding::ISO_8859_1)
|
131
|
+
* #=> "some string"
|
132
|
+
* string.encoding
|
133
|
+
- * #=> #<Encoding:ISO-8859-1>
|
134
|
+
+ * #=> Encoding::ISO_8859_1
|
135
|
+
*
|
136
|
+
* "some string".encode "ISO-8859-1"
|
137
|
+
* #=> "some string"
|
138
|
+
@@ -1672,12 +1677,12 @@
|
139
|
+
* String#force_encoding. This is how you can tell Ruby the correct encoding
|
140
|
+
* of a string.
|
141
|
+
*
|
142
|
+
- * string
|
143
|
+
- * #=> "R\xC3\xA9sum\xC3\xA9"
|
144
|
+
+ * string = "R\xC3\xA9sum\xC3\xA9"
|
145
|
+
* string.encoding
|
146
|
+
- * #=> #<Encoding:ISO-8859-1>
|
147
|
+
- * string.force_encoding(Encoding::UTF-8)
|
148
|
+
- * #=> "R\u00E9sum\u00E9"
|
149
|
+
+ * #=> Encoding::UTF_8
|
150
|
+
+ * string.force_encoding(Encoding::ISO_8859_1)
|
151
|
+
+ * #=> "R\xC3\xA9sum\xC3\xA9"
|
152
|
+
+ * # same bytes!
|
153
|
+
*
|
154
|
+
* Second, it is possible to transcode a string, i.e. translate its internal
|
155
|
+
* byte representation to another encoding. Its associated encoding is also
|
156
|
+
@@ -1685,14 +1690,14 @@
|
157
|
+
* transcoding, and the Encoding::Converter class for additional control over
|
158
|
+
* the transcoding process.
|
159
|
+
*
|
160
|
+
- * string
|
161
|
+
- * #=> "R\u00E9sum\u00E9"
|
162
|
+
+ * string = "R\xC3\xA9sum\xC3\xA9"
|
163
|
+
* string.encoding
|
164
|
+
- * #=> #<Encoding:UTF-8>
|
165
|
+
- * string = string.encode!(Encoding::ISO_8859_1)
|
166
|
+
+ * #=> Encoding::UTF_8
|
167
|
+
+ * string.encode!(Encoding::ISO_8859_1)
|
168
|
+
* #=> "R\xE9sum\xE9"
|
169
|
+
+ * # bytes have been changed!
|
170
|
+
* string.encoding
|
171
|
+
- * #=> #<Encoding::ISO-8859-1>
|
172
|
+
+ * #=> Encoding::ISO_8859_1
|
173
|
+
*
|
174
|
+
* == Script encoding
|
175
|
+
*
|
176
|
+
@@ -1708,7 +1713,7 @@
|
177
|
+
* # encoding: UTF-8
|
178
|
+
*
|
179
|
+
* "some string".encoding
|
180
|
+
- * #=> #<Encoding:UTF-8>
|
181
|
+
+ * #=> Encoding::UTF_8
|
182
|
+
*
|
183
|
+
* The <code>__ENCODING__</code> keyword returns the script encoding of the file
|
184
|
+
* which the keyword is written:
|
185
|
+
@@ -1716,7 +1721,7 @@
|
186
|
+
* # encoding: ISO-8859-1
|
187
|
+
*
|
188
|
+
* __ENCODING__
|
189
|
+
- * #=> #<Encoding:ISO-8859-1>
|
190
|
+
+ * #=> Encoding::ISO_8859_1
|
191
|
+
*
|
192
|
+
* <code>ruby -K</code> will change the default locale encoding, but this is
|
193
|
+
* not recommended. Ruby source files should declare its script encoding by a
|
194
|
+
@@ -1744,17 +1749,17 @@
|
195
|
+
* encoding is set by locale encoding or the interpreter <code>-E</code> option.
|
196
|
+
* Encoding.default_external returns the current value of the external
|
197
|
+
* encoding.
|
198
|
+
- *
|
199
|
+
- * ENV["LANG"]
|
200
|
+
- * #=> "UTF-8"
|
201
|
+
- * Encoding.default_external
|
202
|
+
- * #=> #<Encoding:UTF-8>
|
203
|
+
- *
|
204
|
+
+ *
|
205
|
+
+ * :rdx: off
|
206
|
+
+ *
|
207
|
+
+ * $ LANG="UTF-8" ruby -e 'p Encoding.default_external'
|
208
|
+
+ * #<Encoding:UTF-8>
|
209
|
+
* $ ruby -E ISO-8859-1 -e "p Encoding.default_external"
|
210
|
+
* #<Encoding:ISO-8859-1>
|
211
|
+
- *
|
212
|
+
* $ LANG=C ruby -e 'p Encoding.default_external'
|
213
|
+
* #<Encoding:US-ASCII>
|
214
|
+
+ *
|
215
|
+
+ * :rdx: on
|
216
|
+
*
|
217
|
+
* The default external encoding may also be set through
|
218
|
+
* Encoding.default_external=, but you should not do this as strings created
|
219
|
+
@@ -1788,9 +1793,8 @@
|
220
|
+
*
|
221
|
+
* $ ruby -e 'p Encoding.default_internal'
|
222
|
+
* nil
|
223
|
+
- *
|
224
|
+
* $ ruby -E ISO-8859-1:UTF-8 -e "p [Encoding.default_external, \
|
225
|
+
- * Encoding.default_internal]"
|
226
|
+
+ * > Encoding.default_internal]"
|
227
|
+
* [#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>]
|
228
|
+
*
|
229
|
+
* The default internal encoding may also be set through
|
230
|
+
@@ -1801,8 +1805,14 @@
|
231
|
+
* == IO encoding example
|
232
|
+
*
|
233
|
+
* In the following example a UTF-8 encoded string "R\u00E9sum\u00E9" is transcoded for
|
234
|
+
- * output to ISO-8859-1 encoding, then read back in and transcoded to UTF-8:
|
235
|
+
- *
|
236
|
+
+ * output to ISO-8859-1 encoding, then read back in and transcoded to UTF-8.
|
237
|
+
+ *
|
238
|
+
+ * While writing the file, the internal encoding is not specified as it is
|
239
|
+
+ * only necessary for reading. While reading the file both the internal and
|
240
|
+
+ * external encoding must be specified to obtain the correct result:
|
241
|
+
+ *
|
242
|
+
+ * :rdx: in_tmpdir
|
243
|
+
+ *
|
244
|
+
* string = "R\u00E9sum\u00E9"
|
245
|
+
*
|
246
|
+
* open("transcoded.txt", "w:ISO-8859-1") do |io|
|
247
|
+
@@ -1810,24 +1820,21 @@
|
248
|
+
* end
|
249
|
+
*
|
250
|
+
* puts "raw text:"
|
251
|
+
- * p File.binread("transcoded.txt")
|
252
|
+
+ * puts File.binread("transcoded.txt").dump
|
253
|
+
* puts
|
254
|
+
*
|
255
|
+
* open("transcoded.txt", "r:ISO-8859-1:UTF-8") do |io|
|
256
|
+
* puts "transcoded text:"
|
257
|
+
- * p io.read
|
258
|
+
+ * puts io.read.dump
|
259
|
+
* end
|
260
|
+
*
|
261
|
+
- * While writing the file, the internal encoding is not specified as it is
|
262
|
+
- * only necessary for reading. While reading the file both the internal and
|
263
|
+
- * external encoding must be specified to obtain the correct result.
|
264
|
+
- *
|
265
|
+
- * $ ruby t.rb
|
266
|
+
+ * produces:
|
267
|
+
+ *
|
268
|
+
* raw text:
|
269
|
+
* "R\xE9sum\xE9"
|
270
|
+
*
|
271
|
+
* transcoded text:
|
272
|
+
- * "R\u00E9sum\u00E9"
|
273
|
+
+ * "R\u{e9}sum\u{e9}"
|
274
|
+
*
|
275
|
+
*/
|
276
|
+
|