Module: Finalist
- Defined in:
- lib/finalist.rb,
lib/finalist/version.rb
Defined Under Namespace
Modules: ModuleMethods, SyntaxMethods
Classes: OverrideFinalMethodError
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.extended(base) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/finalist.rb', line 17
def self.extended(base)
super
base.extend(SyntaxMethods)
base.singleton_class.extend(SyntaxMethods)
base.extend(ModuleMethods) if base.instance_of?(Module)
end
|
.finalized_methods ⇒ Object
24
25
26
|
# File 'lib/finalist.rb', line 24
def self.finalized_methods
@finalized_methods ||= {}
end
|
Instance Method Details
#method_added(symbol) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/finalist.rb', line 109
def method_added(symbol)
super
meth = instance_method(symbol)
super_method = meth.super_method
while super_method
if Finalist.finalized_methods[super_method.owner]&.member?(super_method.name)
@__finalist_tp&.disable
@__finalist_tp = nil
raise OverrideFinalMethodError.new("#{super_method} at #{super_method.source_location.join(":")} is overrided\n by #{meth} at #{meth.source_location.join(":")}", self, super_method.owner, meth, :method_added)
end
super_method = super_method.super_method
end
end
|
#singleton_method_added(symbol) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/finalist.rb', line 124
def singleton_method_added(symbol)
super
meth = singleton_class.instance_method(symbol)
super_method = meth.super_method
while super_method
if Finalist.finalized_methods[super_method.owner]&.member?(super_method.name)
@__finalist_tp&.disable
@__finalist_tp = nil
raise OverrideFinalMethodError.new("#{super_method} at #{super_method.source_location.join(":")} is overrided\n by #{meth} at #{meth.source_location.join(":")}", self, super_method.owner, meth, :singleton_method_added)
end
super_method = super_method.super_method
end
end
|