hack weird instantiation bug
self.instance_methods is not always set. tried but didn’t find why any instantiating to circumvent
This commit is contained in:
parent
624699f8ed
commit
a0944266c5
@ -17,9 +17,14 @@ module Parfait
|
|||||||
self.instance_methods = List.new
|
self.instance_methods = List.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def methods
|
||||||
|
m = self.instance_methods
|
||||||
|
return m if m
|
||||||
|
self.instance_methods = List.new
|
||||||
|
end
|
||||||
def method_names
|
def method_names
|
||||||
names = List.new
|
names = List.new
|
||||||
self.instance_methods.each do |method|
|
self.methods.each do |method|
|
||||||
names.push method.name
|
names.push method.name
|
||||||
end
|
end
|
||||||
names
|
names
|
||||||
@ -28,12 +33,14 @@ module Parfait
|
|||||||
def add_instance_method method
|
def add_instance_method method
|
||||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
|
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
|
||||||
raise "syserr #{method.name.class}" unless method.name.is_a? Symbol
|
raise "syserr #{method.name.class}" unless method.name.is_a? Symbol
|
||||||
raise "Adding to wrong class, should be #{method.for_class}" if method.for_class != self
|
if self.is_a?(Class) and (method.for_class != self)
|
||||||
|
raise "Adding to wrong class, should be #{method.for_class}"
|
||||||
|
end
|
||||||
found = get_instance_method( method.name )
|
found = get_instance_method( method.name )
|
||||||
if found
|
if found
|
||||||
self.instance_methods.delete(found)
|
self.methods.delete(found)
|
||||||
end
|
end
|
||||||
self.instance_methods.push method
|
self.methods.push method
|
||||||
#puts "#{self.name} add #{method.name}"
|
#puts "#{self.name} add #{method.name}"
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
@ -41,7 +48,7 @@ module Parfait
|
|||||||
def remove_instance_method method_name
|
def remove_instance_method method_name
|
||||||
found = get_instance_method( method_name )
|
found = get_instance_method( method_name )
|
||||||
if found
|
if found
|
||||||
self.instance_methods.delete(found)
|
self.methods.delete(found)
|
||||||
else
|
else
|
||||||
raise "No such method #{method_name} in #{self.name}"
|
raise "No such method #{method_name} in #{self.name}"
|
||||||
end
|
end
|
||||||
@ -51,7 +58,7 @@ module Parfait
|
|||||||
def get_instance_method fname
|
def get_instance_method fname
|
||||||
raise "get_instance_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
|
raise "get_instance_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
|
||||||
#if we had a hash this would be easier. Detect or find would help too
|
#if we had a hash this would be easier. Detect or find would help too
|
||||||
self.instance_methods.each do |m|
|
self.methods.each do |m|
|
||||||
return m if(m.name == fname )
|
return m if(m.name == fname )
|
||||||
end
|
end
|
||||||
nil
|
nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user