Skip to content

Instantly share code, notes, and snippets.

@enebo
Created March 11, 2009 20:21
Show Gist options
  • Save enebo/77704 to your computer and use it in GitHub Desktop.
Save enebo/77704 to your computer and use it in GitHub Desktop.
# Compiler code
def compile(clazz, signature_provider=nil)
signature_provider=clazz unless signature_provider
clazz.public_instance_methods.each do |name|
signature = signature_provider.signature_for name
# do it...
end
end
# .....Note below signature_for is the only thing the compiler cares about (probably need
# to be something for annotations/class defs as well. 'signature' is merely an example which
# populates something which signature_for can use.
module OrdinarySignatureProvider
def signature_for(name)
@signatures[name]
end
def signature(name, map)
@signatures[name] = map
end
end
# Another neat thing about this is separating signature definitions from the class itself
# Imagine instrospecting a Java type/interface and generating the signatures to apply
# directly to a ruby class which happens to have the same methods. I like this scenario for
# mapping Java types without needing to mark up my Ruby source.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment