Skip to content

Commit b84e6fe

Browse files
authored
[DOC] Mention the omission of a superclass when reopening a class
1 parent e721a7a commit b84e6fe

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

doc/syntax/modules_and_classes.rdoc

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ functionality:
4040
remove_method :my_method
4141
end
4242

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.
4646

4747
== Nesting
4848

@@ -259,6 +259,28 @@ includes a minimum of built-in methods. You can use BasicObject to create an
259259
independent inheritance structure. See the BasicObject documentation for
260260
further details.
261261

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+
262284
== Inheritance
263285

264286
Any method defined on a class is callable from its subclass:

0 commit comments

Comments
 (0)