Created
August 15, 2013 00:54
-
-
Save amatsuda/6237320 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
Kernel.class_eval do | |
#FIXME this is terrible | |
def static(meth) | |
define_singleton_method(meth) do |*args, &b| | |
new.send meth, *args, &b | |
end | |
meth | |
end | |
def abstract(meth) | |
define_method(meth) { raise "Please implement #{self.class.name}##{meth}." } | |
meth | |
end | |
def final(meth) | |
self.extend Module.new { define_method(:method_added) {|added_meth| raise("Overriding or redefining #{meth} is prohibited.") if added_meth == meth; super(added_meth); } } | |
meth | |
end | |
def native(meth) | |
meth | |
end | |
def friend(meth) | |
#TODO | |
meth | |
end | |
def synchronized(meth) | |
#TODO | |
meth | |
end | |
def void(meth) | |
meth | |
end | |
def virtual(meth) | |
meth | |
end | |
def override(meth) | |
raise "#{self.name}##{meth} is not defined." unless ancestors[1..-1].any? {|a| a.method_defined? meth } | |
meth | |
end | |
end | |
class Hello | |
abstract void def aaa | |
p :aaaaa | |
end | |
public static final void def main(*) | |
puts 'hello, world' | |
end | |
end | |
class Hello2 < Hello | |
override def aaa | |
p 'hello2' | |
end | |
end | |
Hello2.new.aaa | |
Hello.main | |
#=> hello, world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
override は arity の一致をチェックしたほうがいいかもしれません。あと、finalと競合するとか。