Actions
Feature #18618
closedno clobber def
Feature #18618:
no clobber def
Status:
Closed
Assignee:
-
Target version:
-
Description
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!
Actions