Issue #8027 has been reported by Hanmac (Hans Mackowiak). ---------------------------------------- Feature #8027: add the possibility to raise an exception in #included, #extended, #prepended, #inherited and break the calling feature https://bugs.ruby-lang.org/issues/8027 Author: Hanmac (Hans Mackowiak) Status: Open Priority: Normal Assignee: Category: core Target version: imo an exception in this hook methods should be possible to prevent the adding in the ancestor chain module A def self.included(mod) raise "dont include me" end end module E include A end ##>> RuntimeError: dont include me E.ancestors #=>[E,A] what i want: E.ancestors #=>[E] maybe other hook methods like method_defined should get an "prevent" option too maybe for not breaking code we could add "before_included" where an exception could be raised
[ruby-trunk - Feature #8027][Open] add the possibility to raise an exception in #included, #extended
on 2013-03-06 09:27
[ruby-trunk - Feature #8027] add the possibility to raise an exception in #included, #extended, #pre
on 2013-03-08 00:51
Issue #8027 has been updated by semaperepelitsa (Semyon Perepelitsa).
I think you are looking for Module.append_features:
module A
def self.append_features(mod)
raise "dont include me"
super
end
end
module E
begin
include A
rescue
end
end
p E.ancestors #=>[E]
If you don't call super it also won't be included.
----------------------------------------
Feature #8027: add the possibility to raise an exception in #included,
#extended, #prepended, #inherited and break the calling feature
https://bugs.ruby-lang.org/issues/8027#change-37371
Author: Hanmac (Hans Mackowiak)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
imo an exception in this hook methods should be possible to prevent the
adding in the ancestor chain
module A
def self.included(mod)
raise "dont include me"
end
end
module E
include A
end
##>> RuntimeError: dont include me
E.ancestors #=>[E,A]
what i want:
E.ancestors #=>[E]
maybe other hook methods like method_defined should get an "prevent"
option too
maybe for not breaking code we could add "before_included" where an
exception could be raised
[ruby-trunk - Feature #8027] add the possibility to raise an exception in #included, #extended, #pre
on 2013-03-08 08:46
Issue #8027 has been updated by Hanmac (Hans Mackowiak). ah good to know, but not the best way. What if i want that a Module is extendable but not includable? Then append_features may not what i want ---------------------------------------- Feature #8027: add the possibility to raise an exception in #included, #extended, #prepended, #inherited and break the calling feature https://bugs.ruby-lang.org/issues/8027#change-37384 Author: Hanmac (Hans Mackowiak) Status: Open Priority: Normal Assignee: Category: core Target version: imo an exception in this hook methods should be possible to prevent the adding in the ancestor chain module A def self.included(mod) raise "dont include me" end end module E include A end ##>> RuntimeError: dont include me E.ancestors #=>[E,A] what i want: E.ancestors #=>[E] maybe other hook methods like method_defined should get an "prevent" option too maybe for not breaking code we could add "before_included" where an exception could be raised
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.