[#108552] [Ruby master Bug#18782] Race conditions in autoload when loading the same feature with multiple threads. — "ioquatix (Samuel Williams)" <noreply@...>
Issue #18782 has been reported by ioquatix (Samuel Williams).
11 messages
2022/05/14
[ruby-core:108621] [Ruby master Feature#18618] no clobber def
From:
"matz (Yukihiro Matsumoto)" <noreply@...>
Date:
2022-05-19 08:13:22 UTC
List:
ruby-core #108621
Issue #18618 has been updated by matz (Yukihiro Matsumoto).
Status changed from Open to Closed
See [#18742](https://bugs.ruby-lang.org/issues/18742#note-4)
Matz.
----------------------------------------
Feature #18618: no clobber def
https://bugs.ruby-lang.org/issues/18618#change-97657
* Author: ed_ (Ed Mangimelli)
* Status: Closed
* 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
=> #<MethodAlreadyDefined: Method `bark' already defined.>
```
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: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>