cleaner way to generate argument types

possibly more correct
This commit is contained in:
Torsten Ruger 2016-12-30 19:17:59 +02:00
parent 83b6628f1a
commit a7935db107
2 changed files with 9 additions and 5 deletions

View File

@ -23,5 +23,9 @@
module Parfait module Parfait
class NamedList < Object class NamedList < Object
def self.type_for( arguments )
my_class = Parfait.object_space.classes[:NamedList]
Parfait::Type.for_hash( my_class , arguments.merge(type: my_class.instance_type))
end
end end
end end

View File

@ -40,7 +40,7 @@ module Parfait
attr_reader :object_class , :names , :types , :methods attr_reader :object_class , :names , :types , :methods
def self.for_hash( object_class , hash) def self.for_hash( object_class , hash)
hash[:type] = :Type unless hash[:type] hash = {type: object_class.name }.merge(hash) unless hash[:type]
new_type = Type.new( object_class , hash) new_type = Type.new( object_class , hash)
code = hash_code_for_hash( hash ) code = hash_code_for_hash( hash )
Parfait.object_space.types[code] = new_type Parfait.object_space.types[code] = new_type
@ -105,9 +105,9 @@ module Parfait
def create_method( method_name , arguments ) def create_method( method_name , arguments )
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol) raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
#puts "Self: #{self.class} clazz: #{clazz.name}" #puts "Self: #{self.class} clazz: #{clazz.name}"
type = arguments arg_type = arguments
type = Parfait::Type.for_hash( @object_class , arguments) if arguments.is_a?(Hash) arg_type = NamedList.type_for( arguments ) if arguments.is_a?(Hash)
add_method TypedMethod.new( self , method_name , type ) add_method TypedMethod.new( self , method_name , arg_type )
end end
def add_method( method ) def add_method( method )