JRuby hacking guide
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,841
On Slideshare
1,840
From Embeds
1
Number of Embeds
1

Actions

Shares
Downloads
15
Comments
0
Likes
3

Embeds 1

https://twitter.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. JRuby hacking guideDavid Calavera@calavera
  • 2. +70contributors
  • 3. 9coremembers
  • 4. ~ 30singlecommits
  • 5. we wantyou
  • 6. core
  • 7. rule ofthumb
  • 8. jruby-1.6.2 :003 > raise ArgumentError.newArgumentError: ArgumentError from (irb):3:in `evaluate from org/jruby/RubyKernel.java:1088:in `e from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:158:in `eval_input from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:271:in `signal_status from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:155:in `eval_input from org/jruby/RubyKernel.java:1419:in `l from org/jruby/RubyKernel.java:1191:in `c from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:154:in `eval_input from /Users/david/.rvm/rubies/jruby-1.6.2
  • 9. do notfreak out
  • 10. ruby-1.8.7 :001 > raise ArgumentError.newArgumentError: ArgumentError from (irb):1
  • 11. jruby-1.6.2 :001 > raise ArgumentError.newArgumentError: ArgumentError from (irb):1:in `evaluate from org/jruby/RubyKernel.java:1088:in `e from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:158:in `eval_input from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:271:in `signal_status from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:155:in `eval_input from org/jruby/RubyKernel.java:1419:in `l from org/jruby/RubyKernel.java:1191:in `c from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:154:in `eval_input from /Users/david/.rvm/rubies/jruby-1.6.2
  • 12. jruby-1.6.2 :001 > raise ArgumentError.newArgumentError: ArgumentError from (irb):1:in `evaluate from org/jruby/RubyKernel.java:1088:in `e from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:158:in `eval_input from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:271:in `signal_status from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:155:in `eval_input from org/jruby/RubyKernel.java:1419:in `l from org/jruby/RubyKernel.java:1191:in `c from /Users/david/.rvm/rubies/jruby-1.6.2irb.rb:154:in `eval_input from /Users/david/.rvm/rubies/jruby-1.6.2
  • 13. your rubycode is ourtest case
  • 14. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 15. Rspecdescribe "glob file path" do it "lists contents of a file" do dir = Dir.new(@local_file_path) dir.entries.should include("junit.jar") endend
  • 16. followthespecification
  • 17. RubySpecdescribe "Dir.entries" do ... it "returns an Array of filenames in anexisting directory including dotfiles" do ...
  • 18. RubySpecdescribe "Dir.entries" do ... ruby_version_is "1.9" do it "calls #to_path on ..." do ...
  • 19. RubySpec$ bin/jruby -S mspec spec/ruby/core/dir/entries_spec.rb$ bin/jruby --1.9 -S mspec spec/ruby/core/dir/entries_spec.rb
  • 20. go to thesource
  • 21. ruby codestatic VALUEdir_entries(int argc, VALUE *argv, VALUE io){ VALUE dir; dir = dir_open_dir(argc, argv); return rb_ensure(rb_Array, dir, dir_close, dir);}
  • 22. tamingthe beast
  • 23. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 24. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 25. Ruby class$ vi src/org/jruby/RubyDir.java@JRubyClass(name = "Dir", include = "Enumerable")public class RubyDir extends RubyObject {
  • 26. Ruby class$ vi src/org/jruby/RubyDir.java@JRubyClass(name = "Dir", include = "Enumerable")public class RubyDir extends RubyObject {
  • 27. Ruby class$ vi src/org/jruby/RubyDir.java@JRubyClass(name = "Dir", include = "Enumerable")public class RubyDir extends RubyObject {
  • 28. Ruby class$ vi src/org/jruby/RubyDir.java@JRubyClass(name = "Dir", include = "Enumerable")public class RubyDir extends RubyObject {
  • 29. Ruby class$ vi src/org/jruby/RubyDir.java@JRubyClass(name = "Dir", include = "Enumerable")public class RubyDir extends RubyObject {
  • 30. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 31. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 32. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 33. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 34. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 35. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 36. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 37. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 38. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 39. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 40. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 41. Ruby method@JRubyMethod(name = "mkdir", required = 1,optional = 1, meta = true, compat = RUBY1_8)public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
  • 42. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 43. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 44. initializeprivate static final ObjectAllocator DIR_ALLOCATOR = new ObjectAllocator()@JRubyMethod(compat = RUBY1_8)public IRubyObject initialize(IRubyObject arg)
  • 45. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 46. Test::Unitdef test_dir_enumerable Dir.mkdir("./testDir_1") d = Dir.new("./testDir_1") assert(d.kind_of?(Enumerable))end
  • 47. Ruby module$ vi src/org/jruby/RubyKernel.java@JRubyModule(name="Kernel")public class RubyKernel {
  • 48. Ruby module$ vi src/org/jruby/RubyKernel.java@JRubyModule(name="Kernel")public class RubyKernel {
  • 49. Ruby module$ vi src/org/jruby/RubyObject.java@JRubyClass(name="Object", include="Kernel")public class RubyObject extends ... {
  • 50. Ruby module@JRubyMethod(name = {"kind_of?", "is_a?"}, required = 1)public static RubyBoolean kind_of_p(ThreadContext context, IRubyObject recv, IRubyObject type) {
  • 51. Ruby module@JRubyMethod(name = {"kind_of?", "is_a?"}, required = 1)public static RubyBoolean kind_of_p(ThreadContext context, IRubyObject recv, IRubyObject type) {
  • 52. Ruby module@JRubyMethod(name = {"kind_of?", "is_a?"}, required = 1)public static RubyBoolean kind_of_p(ThreadContext context, IRubyObject recv, IRubyObject type) {
  • 53. learn more
  • 54. http://tinyurl.com/jruby-hacking-guide by Hiroshi Nakamura
  • 55. http://tinyurl.com/ distilling-jruby by R.J. Lorimer
  • 56. http://jruby.org
  • 57. thank you!
  • 58. CreditsCharles Nutter’s Photo Boothhttp://www.flickr.com/photos/zpeckler/2648345658/http://www.flickr.com/photos/dcmetroblogger/3298543398/http://www.flickr.com/photos/jenny-pics/4520503357/