File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -40,9 +40,9 @@ functionality:
40
40
remove_method :my_method
41
41
end
42
42
43
- Reopening classes is a very powerful feature of Ruby, but it is best to only
44
- reopen classes you own. Reopening classes you do not own may lead to naming
45
- conflicts or difficult to diagnose bugs.
43
+ Reopening modules (or classes) is a very powerful feature of Ruby, but it is
44
+ best to only reopen modules you own. Reopening modules you do not own may lead
45
+ to naming conflicts or difficult to diagnose bugs.
46
46
47
47
== Nesting
48
48
@@ -259,6 +259,28 @@ includes a minimum of built-in methods. You can use BasicObject to create an
259
259
independent inheritance structure. See the BasicObject documentation for
260
260
further details.
261
261
262
+ Just like modules, classes can also be reopened. You can omit its superclass
263
+ when you reopen a class. Specifying a different superclass than the previous
264
+ definition will raise an error.
265
+
266
+ class C
267
+ end
268
+
269
+ class D < C
270
+ end
271
+
272
+ # OK
273
+ class D < C
274
+ end
275
+
276
+ # OK
277
+ class D
278
+ end
279
+
280
+ # TypeError: superclass mismatch for class D
281
+ class D < String
282
+ end
283
+
262
284
== Inheritance
263
285
264
286
Any method defined on a class is callable from its subclass:
You can’t perform that action at this time.
0 commit comments