From: "ed_ (Ed Mangimelli)" Date: 2022-03-10T06:12:47+00:00 Subject: [ruby-core:107816] [Ruby master Feature#18618] no clobber def Issue #18618 has been updated by ed_ (Ed Mangimelli). @Dan0042 I like that syntax --much more convenient-- but I don't know if it would be useful to me if it were just toggling the existing warning. But that syntax seems great: ```ruby class MyClass < LibraryProvidedClass no_clobber def a; end def b; super; end # no effect (`super` being called) def c; end override def d; end # maybe an override keyword to use in conjunction with `no_clobber`? end => # ``` ```ruby class MyClass < LibraryProvidedClass def a; end no_clobber def b; end # can also be used in a one-off way like `private` def c; end end ``` ---------------------------------------- Feature #18618: no clobber def https://bugs.ruby-lang.org/issues/18618#change-96746 * Author: ed_ (Ed Mangimelli) * Status: Open * Priority: Normal ---------------------------------------- Sometimes I want to be certain I'm not clobbering/masking a method: ``` class Dog def bark 'bark!' end end class Poodle < Dog raise if method_defined? :bark def bark 'bow-wow' end end ``` I propose creating a shorthand. Maybe something like: ``` class Dog def bark 'bark!' end end class Poodle < Dog ncdef bark # "no clobber" def 'bow-wow' end end => # ``` This would be useful in scenarios where subclassing a class (or including a mixin) ***you don't own*** is common practice --for instance, subclassing `ApplicationRecord` for your model in Rails. I agree that `ncdef` is pretty ugly. Maybe `def!` -- https://bugs.ruby-lang.org/ Unsubscribe: