2016-12-06 10:38:09 +01:00
|
|
|
# Behaviour is something that has methods, basically class and modules superclass
|
2015-10-26 12:27:56 +01:00
|
|
|
|
2016-12-06 10:38:09 +01:00
|
|
|
# instance_methods is the attribute in the including class that has the methods
|
2015-10-26 12:27:56 +01:00
|
|
|
|
|
|
|
module Parfait
|
|
|
|
module Behaviour
|
|
|
|
|
2015-10-26 13:33:36 +01:00
|
|
|
def initialize
|
|
|
|
super()
|
2019-09-10 11:33:57 +02:00
|
|
|
@instance_methods = List.new
|
2015-10-26 13:33:36 +01:00
|
|
|
end
|
|
|
|
|
2015-10-26 16:23:02 +01:00
|
|
|
def methods
|
2019-09-10 11:33:57 +02:00
|
|
|
m = @instance_methods
|
2015-10-26 16:23:02 +01:00
|
|
|
return m if m
|
2019-09-10 11:33:57 +02:00
|
|
|
@instance_methods = List.new
|
2015-10-26 16:23:02 +01:00
|
|
|
end
|
2016-12-06 10:38:09 +01:00
|
|
|
|
2015-10-26 12:27:56 +01:00
|
|
|
def method_names
|
|
|
|
names = List.new
|
2019-09-09 19:26:54 +02:00
|
|
|
methods.each do |method|
|
2015-10-26 12:27:56 +01:00
|
|
|
names.push method.name
|
|
|
|
end
|
|
|
|
names
|
|
|
|
end
|
|
|
|
|
2016-12-15 13:00:34 +01:00
|
|
|
def add_instance_method( method )
|
2018-06-27 16:09:50 +02:00
|
|
|
raise "not implemented #{method.class} #{method.inspect}" unless method.is_a? VoolMethod
|
2019-09-10 11:33:57 +02:00
|
|
|
raise "HMM"
|
2015-10-26 12:27:56 +01:00
|
|
|
method
|
|
|
|
end
|
|
|
|
|
2016-12-15 13:00:34 +01:00
|
|
|
def remove_instance_method( method_name )
|
2015-10-26 12:27:56 +01:00
|
|
|
found = get_instance_method( method_name )
|
2019-09-10 11:33:57 +02:00
|
|
|
found ? methods.delete(found) : false
|
2015-10-26 12:27:56 +01:00
|
|
|
end
|
|
|
|
|
2016-12-15 13:00:34 +01:00
|
|
|
def get_instance_method( fname )
|
2015-10-26 12:27:56 +01:00
|
|
|
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
|
2019-09-09 19:26:54 +02:00
|
|
|
@instance_methods.find {|m| m.name == fname }
|
2015-10-26 12:27:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# get the method and if not found, try superclasses. raise error if not found
|
2018-04-02 16:06:31 +02:00
|
|
|
def resolve_method( m_name )
|
2015-10-26 12:27:56 +01:00
|
|
|
raise "resolve_method #{m_name}.#{m_name.class}" unless m_name.is_a?(Symbol)
|
|
|
|
method = get_instance_method(m_name)
|
|
|
|
return method if method
|
2019-02-16 22:24:16 +01:00
|
|
|
if( super_class_name && super_class_name != :Object )
|
2019-09-09 19:26:54 +02:00
|
|
|
method = @super_class.resolve_method(m_name)
|
2015-10-26 12:27:56 +01:00
|
|
|
end
|
|
|
|
method
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|