Created
April 5, 2011 19:24
-
-
Save qmx/904322 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@JRubyClass(name = "Date") | |
public class RubyDate extends RubyObject { | |
public static class RubyDateSingleton { | |
@JRubyMethod(name = "jd_to_civil", required = 1, optional = 1, visibility = Visibility.PRIVATE) | |
public IRubyObject jd_to_civil(ThreadContext ctx, IRubyObject[] args) { | |
System.out.println("LOOOOL"); | |
return ctx.nil; | |
} | |
} | |
private static final ObjectAllocator DATE_ALLOCATOR = new ObjectAllocator() { | |
public IRubyObject allocate(Ruby runtime, RubyClass klass) { | |
return new RubyDate(runtime, klass); | |
} | |
}; | |
public static RubyClass createDate(Ruby runtime) { | |
RubyClass result = runtime.defineClass("Date", runtime.getObject(), DATE_ALLOCATOR); | |
result.defineAnnotatedMethods(RubyDate.class); | |
result.defineAnnotatedConstants(RubyDate.class); | |
RubyModule module = RubyModule.newModule(runtime); | |
module.defineAnnotatedMethods(RubyDateSingleton.class); | |
result.include(new IRubyObject[] { module }); | |
result.extend(new IRubyObject[] { module }); | |
result.getSingletonClass().include(new IRubyObject[] { module }); | |
result.getSingletonClass().extend(new IRubyObject[] { module }); | |
return result; | |
} | |
public RubyDate(Ruby runtime, RubyClass klass) { | |
super(runtime, klass); | |
} |
This file contains hidden or 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 'date' | |
> Date.new | |
NoMethodError: undefined method `jd_to_civil' for Date:Class | |
from /Volumes/v2/git/jruby/lib/ruby/1.9/date.rb:625:in `_valid_civil?' | |
from /Volumes/v2/git/jruby/lib/ruby/1.9/date.rb:808:in `civil' | |
from (irb):2:in `evaluate' | |
from org/jruby/RubyKernel.java:1087:in `eval' | |
from org/jruby/RubyKernel.java:1412:in `loop' | |
from org/jruby/RubyKernel.java:1199:in `catch' | |
from org/jruby/RubyKernel.java:1199:in `catch' | |
from /Volumes/v2/git/jruby/bin/jirb:13:in `(root)' |
This file contains hidden or 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
t = Module.new do | |
private | |
def jd_to_civil(a,b) | |
... | |
end | |
end | |
Date.extend(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment