diff options
author | Kouhei Yanagita <yanagi@shakenbu.org> | 2023-10-22 20:12:16 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-22 20:12:16 +0900 |
commit | b84e6fe93ee35111b592f9e10e30bc460a077d0b (patch) | |
tree | 8b9f12cfd39ef1c93e51d89bcb877a922b5b7668 | |
parent | e721a7aec77754f42a44e05d115adb7ae676197c (diff) | |
download | ruby-b84e6fe93ee35111b592f9e10e30bc460a077d0b.tar.gz |
[DOC] Mention the omission of a superclass when reopening a class
-rw-r--r-- | doc/syntax/modules_and_classes.rdoc | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/doc/syntax/modules_and_classes.rdoc b/doc/syntax/modules_and_classes.rdoc index 024815a5a6..9e05c5c774 100644 --- a/doc/syntax/modules_and_classes.rdoc +++ b/doc/syntax/modules_and_classes.rdoc @@ -40,9 +40,9 @@ functionality: remove_method :my_method end -Reopening classes is a very powerful feature of Ruby, but it is best to only -reopen classes you own. Reopening classes you do not own may lead to naming -conflicts or difficult to diagnose bugs. +Reopening modules (or classes) is a very powerful feature of Ruby, but it is +best to only reopen modules you own. Reopening modules you do not own may lead +to naming conflicts or difficult to diagnose bugs. == Nesting @@ -259,6 +259,28 @@ includes a minimum of built-in methods. You can use BasicObject to create an independent inheritance structure. See the BasicObject documentation for further details. +Just like modules, classes can also be reopened. You can omit its superclass +when you reopen a class. Specifying a different superclass than the previous +definition will raise an error. + + class C + end + + class D < C + end + + # OK + class D < C + end + + # OK + class D + end + + # TypeError: superclass mismatch for class D + class D < String + end + == Inheritance Any method defined on a class is callable from its subclass: |