Skip to content

Instantly share code, notes, and snippets.

@amatsuda
Created August 15, 2013 00:54
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amatsuda/6237320 to your computer and use it in GitHub Desktop.
Save amatsuda/6237320 to your computer and use it in GitHub Desktop.
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
@sakuro
Copy link

sakuro commented Aug 15, 2013

override は arity の一致をチェックしたほうがいいかもしれません。あと、finalと競合するとか。

@tadd
Copy link

tadd commented Jan 18, 2014

overrideはやっぱり、@Overrideにした方が!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment