Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created March 29, 2014 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/3abeb48c4f4f6316dbaf to your computer and use it in GitHub Desktop.
Save rightfold/3abeb48c4f4f6316dbaf to your computer and use it in GitHub Desktop.
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