-
-
Save rightfold/3abeb48c4f4f6316dbaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
module Styx | |
class Interface | |
attr_reader :methods | |
def initialize | |
@methods = {} | |
end | |
end | |
class Struct | |
attr_reader :fields | |
def initialize | |
@fields = {} | |
end | |
end | |
class Method | |
attr_reader :parameters | |
def initialize(parameters) | |
@parameters = parameters | |
end | |
end | |
class MethodImplementation | |
attr_reader :method, :parameter_types | |
def initialize(method, parameter_types) | |
@method = method | |
@parameter_types = parameter_types | |
end | |
end | |
class Context | |
attr_accessor :interfaces, :structs, :methods | |
def initialize | |
@interfaces = Set.new | |
@structs = Set.new | |
@methods = {} | |
end | |
def implements_interface?(struct, interface) | |
interface.methods.all? do |[method, param_types]| | |
expected_param_types = param_types.map{ |param_type| param_type || struct } | |
@methods[method].include? expected_param_types | |
end | |
end | |
def implementing_structs(interface) | |
@structs.filter{ |struct| implements?(struct, interface) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment