MacRuby on Rails                2011 3             MacRuby     Ruby                                    Ruby on Rails      ...
•                • cRuby             Readline                • MacRuby                • @takaokouji(@takaokouji_en)       ...
2011   7   19   3
•2011   7   19       3
•                    Network Applied Communicaiton Laboratory Co,.Ltd.2011   7   19                                       ...
•                    Network Applied Communicaiton Laboratory Co,.Ltd.                •2011   7   19                      ...
•                    Network Applied Communicaiton Laboratory Co,.Ltd.                •2011   7   19                      ...
•                    Network Applied Communicaiton Laboratory Co,.Ltd.                •2011   7   19                      ...
MacRuby on Rails2011   7   19                      4
MacRuby on Rails2011   7   19                      4
MacRuby                Mac OS X   Ruby2011   7   19                     5
MacRuby2011   7   19             6
MacRuby                MacRuby is a unique blend of Ruby 1.9 and                Objective-C.                ➡ Ruby 1.9 Obj...
MacRuby                MacRuby is a unique blend of Ruby 1.9 and                Objective-C.                ➡ Ruby 1.9 Obj...
Ruby 1.9                           Ruby 1.9                Ruby VM                                        GC              ...
MacRuby                          MacRuby                Ruby VM                                     GC                    ...
MacRuby                          MacRuby                Ruby VM                                     GC                    ...
MacRuby                          MacRuby                Ruby VM                                     AutoZone              ...
MacRuby                             MacRuby                   Ruby VM                                        AutoZone     ...
MacRuby                               MacRuby                                               AutoZone                      ...
MacRuby×Cocoa                framework “cocoa”                def playSound(name)                 sound = NSSound.soundNam...
HelloMacRuby2011   7   19                  11
HelloMacRuby2011   7   19                  11
HelloMacRuby                        Hello,MacRuby!                Hello,MacRuby!2011   7   19                            11
HelloMacRuby                Ruby                class AppController                  attr_accessor :textField             ...
HelloMacRuby                Ruby                class AppController                  attr_accessor :textField             ...
HelloMacRuby                Ruby                class AppController                  attr_accessor :textField             ...
MacRuby on Rails                MacRuby Ruby on Rails2011   7   19                           13
MacRuby on Rails2011   7   19                      14
MacRuby on Rails                $ rails new demo2011   7   19                             14
MacRuby on Rails                $ rails new demo                      $ rails generate scaffold ...2011   7   19          ...
MacRuby on Rails                $ rails new demo                      $ rails generate scaffold ...                       ...
MacRuby on Rails                $ rails new demo                      $ rails generate scaffold ...                       ...
4   ...2011   7   19             15
4   ...                2011   32011   7   19                        15
4      ...                2011   3                • MacRuby Rails2011   7   19                           15
4                         ...                2011      3                • MacRuby Rails                • Rails            ...
...2011   7   19         16
...                •   Rails2011   7   19                     16
...                •              Rails                •                $ macruby -S rails new demo                     cr...
2011   7   19   17
• scaffold ...2011   7   19                    17
• scaffold ...                • abort                $ macruby -S rails generate scaffold Bookmark title:string           ...
• scaffold ...                • abort                $ macruby -S rails generate scaffold Bookmark title:string           ...
Rails                SEGV    abort                 RubySpec                Rails2011   7   19                   18
Rails                SEGV    abort                                •   cRuby                                •   Objective-C...
#860 catch/throw                Assertion fails in pop_current_exception                when catch/throw used in rescue   ...
#860 catch/throw                Assertion fails in pop_current_exception                when catch/throw used in rescue   ...
#860 catch/throw                Assertion fails in pop_current_exception                when catch/throw used in rescue   ...
#860 catch/throw                Assertion fails in pop_current_exception                when catch/throw used in rescue   ...
#860 catch/throw                Assertion fails in pop_current_exception                when catch/throw used in rescue   ...
#860 catch/throw                 (60723bf~)   throw2011   7   19                         20
#860 catch/throw                          (60723bf~)   throw                catch(:ambiguous) {                  begin    ...
#860 catch/throw                          (60723bf~)   throw                catch(:ambiguous) {                  begin    ...
#860 catch/throw                          (60723bf~)          throw                catch(:ambiguous) {                  be...
#860 catch/throw                               (60723bf~)                  throw                vm.cpp:4321:              ...
#860 catch/throw                ➡                     (60723bf)2011   7   19                          21
#860 catch/throw                  ➡                             (60723bf)                vm.cpp:4318:                VALUE...
#860 catch/throw                  ➡                             (60723bf)                                 catch           ...
#860 catch/throw                begin                 raise                rescue                 catch(:ambiguous) {     ...
#860 catch/throw                begin          A                 raise                rescue                 catch(:ambigu...
#860 catch/throw                begin          A                 raise                        A                rescue     ...
#860 catch/throw                begin          A                 raise                        A                rescue     ...
#860 catch/throw                begin          A                 raise                        A                rescue     ...
#860 catch/throw                begin          A                 raise                        A                rescue     ...
#860 catch/throw                begin           A                 raise                        A                rescue    ...
#1192                Did not find nested constants.                ➡2011   7   19                                   23
#1192                Did not find nested constants.                ➡                module A                 B = 10        ...
#1192                Did not find nested constants.                ➡                module A                 B = 10        ...
#1192                Did not find nested constants.                ➡                module A                               ...
#1192                  6b101bd~2011   7   19                24
#1192                            6b101bd~                module A                 module B                  CONST = “B’s C...
#1192                              6b101bd~                module A                 module B                  CONST = “B’s...
#1192                              6b101bd~                module A                 module B                  CONST = “B’s...
module_eval(            )   module_eval                module A                    module A                 CONST = "As CO...
module_eval(            )    module_eval                module A                     module A                 CONST = "As ...
module_eval(            )    module_eval                module A                     module A                 CONST = "As ...
module_eval(            )    module_eval                module A                     module A                 CONST = "As ...
module_eval(            )    module_eval                module A                     module A                 CONST = "As ...
2011   7   19   26
module A                 B = 42                end                A.class_eval do                 def self.f              ...
module A                 B = 42                                  Ruby 1.9                end               42             ...
module A                 B = 42                                  Ruby 1.9                end               42             ...
module A                 B = 42                                  y                                  Ruby 1.9              ...
#                abort when I pressed “About your                application’s environment” in welcome page.              ...
#                abort when I pressed “About your                application’s environment” in welcome page.              ...
#                abort when I pressed “About your                application’s environment” in welcome page.              ...
#                abort when I pressed “About your                application’s environment” in welcome page.              ...
...2011   7   19         28
...                MacRuby Rails         ...2011   7   19                               28
...                MacRuby Rails         ...                ➡2011   7   19                               28
...                MacRuby Rails                       ...                ➡                ➡ @lrz                    Rails...
RubyConf ...                 To be continued...                             <morohoshi@netlab.jp>2011   7   19            ...
Upcoming SlideShare
Loading in …5
×

MacRuby on Rails

2,488 views

Published on

MacRuby is an implementation of Ruby 1.9 that is directly on top of Mac OS X core technologies. Recently, MacRuby has become viable as a tool for developing useful desktop applications for Mac OS X. However, as of March 2011, MacRuby is still missing some functionality that is present in cRuby. Therefore, MacRuby is not able to run Ruby on Rails. In my presentation, I will explain how I modified MacRuby to make it a suitable foundation for running Rails. I would also like to explain some of technical intricacies that I discovered along the way.

(Japanese)
2011年3月時点でのMacRubyはRuby処理系としての完成度は低く、Ruby on Railsが到底動作するようには思えない。しかしながら、MacRubyに対して改良 に改良を重ねることできっとRailsを動作させることができる(はずである)。 本発表ではMacRubyでRailsを動作させるために必要だった修正内容とともに、 その過程であらためて知ることになったcRubyのすばらしさを説明します。

Published in: Technology
  • Be the first to comment

MacRuby on Rails

  1. 1. MacRuby on Rails 2011 3 MacRuby Ruby Ruby on Rails MacRuby Rails MacRuby Rails cRuby Abstract MacRuby is an implementation of Ruby 1.9 that is directly on top of Mac OS X core technologies. Recently, MacRuby has become viable as a tool for developing useful desktop applications for Mac OS X. However, as of March 2011, MacRuby is still missing some functionality that is present in cRuby. Therefore, MacRuby is not able to run Ruby on Rails. In my presentation, I will explain how I modified MacRuby to make it a suitable foundation for running Rails. I would also like to explain some of technical intricacies that I discovered along the way.2011 7 19 1
  2. 2. • • cRuby Readline • MacRuby • @takaokouji(@takaokouji_en) • http://facebook.com/takaokouji2011 7 19 2
  3. 3. 2011 7 19 3
  4. 4. •2011 7 19 3
  5. 5. • Network Applied Communicaiton Laboratory Co,.Ltd.2011 7 19 3
  6. 6. • Network Applied Communicaiton Laboratory Co,.Ltd. •2011 7 19 3
  7. 7. • Network Applied Communicaiton Laboratory Co,.Ltd. •2011 7 19 3
  8. 8. • Network Applied Communicaiton Laboratory Co,.Ltd. •2011 7 19 3
  9. 9. MacRuby on Rails2011 7 19 4
  10. 10. MacRuby on Rails2011 7 19 4
  11. 11. MacRuby Mac OS X Ruby2011 7 19 5
  12. 12. MacRuby2011 7 19 6
  13. 13. MacRuby MacRuby is a unique blend of Ruby 1.9 and Objective-C. ➡ Ruby 1.9 Objective-C2011 7 19 6
  14. 14. MacRuby MacRuby is a unique blend of Ruby 1.9 and Objective-C. ➡ Ruby 1.9 Objective-C The goal of the MacRuby project is to be 100% compatible syntactically and behaviorally with Ruby 1.9. ➡ Ruby 1.92011 7 19 6
  15. 15. Ruby 1.9 Ruby 1.9 Ruby VM GC OS (Linux,Windows,Mac OS X,etc...)2011 7 19 7
  16. 16. MacRuby MacRuby Ruby VM GC Mac OS X2011 7 19 8
  17. 17. MacRuby MacRuby Ruby VM GC Mac OS X2011 7 19 8
  18. 18. MacRuby MacRuby Ruby VM AutoZone GC Mac OS X2011 7 19 8
  19. 19. MacRuby MacRuby Ruby VM AutoZone GC Foundation Mac OS X2011 7 19 8
  20. 20. MacRuby MacRuby AutoZone LLVM GC Foundation Mac OS X2011 7 19 9
  21. 21. MacRuby×Cocoa framework “cocoa” def playSound(name) sound = NSSound.soundNamed(name) sound.play end2011 7 19 10
  22. 22. HelloMacRuby2011 7 19 11
  23. 23. HelloMacRuby2011 7 19 11
  24. 24. HelloMacRuby Hello,MacRuby! Hello,MacRuby!2011 7 19 11
  25. 25. HelloMacRuby Ruby class AppController attr_accessor :textField def hello(sender) @textField.stringValue = "Hello,MacRuby!" end end2011 7 19 12
  26. 26. HelloMacRuby Ruby class AppController attr_accessor :textField def hello(sender) @textField.stringValue = "Hello,MacRuby!" end end2011 7 19 12
  27. 27. HelloMacRuby Ruby class AppController attr_accessor :textField def hello(sender) @textField.stringValue = "Hello,MacRuby!" end end2011 7 19 12
  28. 28. MacRuby on Rails MacRuby Ruby on Rails2011 7 19 13
  29. 29. MacRuby on Rails2011 7 19 14
  30. 30. MacRuby on Rails $ rails new demo2011 7 19 14
  31. 31. MacRuby on Rails $ rails new demo $ rails generate scaffold ...2011 7 19 14
  32. 32. MacRuby on Rails $ rails new demo $ rails generate scaffold ... $ rails server2011 7 19 14
  33. 33. MacRuby on Rails $ rails new demo $ rails generate scaffold ... $ rails server2011 7 19 14
  34. 34. 4 ...2011 7 19 15
  35. 35. 4 ... 2011 32011 7 19 15
  36. 36. 4 ... 2011 3 • MacRuby Rails2011 7 19 15
  37. 37. 4 ... 2011 3 • MacRuby Rails • Rails $ sudo macgem install --verbose rails --no-ri --no-rdoc 7 gems installed $ sudo macgem install --verbose sqlite3-ruby --no-ri --no-rdoc 2 gems installed2011 7 19 15
  38. 38. ...2011 7 19 16
  39. 39. ... • Rails2011 7 19 16
  40. 40. ... • Rails • $ macruby -S rails new demo create create README create Rakefile ... create vendor/plugins create vendor/plugins/.gitkeep2011 7 19 16
  41. 41. 2011 7 19 17
  42. 42. • scaffold ...2011 7 19 17
  43. 43. • scaffold ... • abort $ macruby -S rails generate scaffold Bookmark title:string description:text url:string ... Assertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3434. zsh: abort macruby -S rails generate scaffold Bookmark title:string description:text2011 7 19 17
  44. 44. • scaffold ... • abort $ macruby -S rails generate scaffold Bookmark title:string description:text url:string $ macruby -S rails server ... ... Assertion failed: ((size_t)pos < current_exceptions.size()), Assertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3434. function pop_current_exception, file vm.cpp, line 3434. zsh: abort macruby -S rails generate scaffold Bookmark zsh: abort macruby -S rails server title:string description:text2011 7 19 17
  45. 45. Rails SEGV abort RubySpec Rails2011 7 19 18
  46. 46. Rails SEGV abort • cRuby • Objective-C • C++ • LLVM RubySpec Rails2011 7 19 18
  47. 47. #860 catch/throw Assertion fails in pop_current_exception when catch/throw used in rescue ➡ rescue catch throw abort2011 7 19 19
  48. 48. #860 catch/throw Assertion fails in pop_current_exception when catch/throw used in rescue ➡ rescue catch throw abort begin raise rescue catch(:ambiguous) { throw :ambiguous } p :ok end2011 7 19 19
  49. 49. #860 catch/throw Assertion fails in pop_current_exception when catch/throw used in rescue ➡ rescue catch throw abort begin raise rescue catch(:ambiguous) { throw :ambiguous } p :ok end :ok Assertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3448.2011 7 19 19
  50. 50. #860 catch/throw Assertion fails in pop_current_exception when catch/throw used in rescue ➡ rescue catch throw abort throw begin raise rescue catch(:ambiguous) { throw :ambiguous } p :ok end :ok Assertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3448.2011 7 19 19
  51. 51. #860 catch/throw Assertion fails in pop_current_exception when catch/throw used in rescue ➡ rescue catch throw abort throw begin raise rescue catch(:ambiguous) { throw :ambiguous } p :ok end :ok abort Assertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3448.2011 7 19 19
  52. 52. #860 catch/throw (60723bf~) throw2011 7 19 20
  53. 53. #860 catch/throw (60723bf~) throw catch(:ambiguous) { begin raise rescue throw :ambiguou end }2011 7 19 20
  54. 54. #860 catch/throw (60723bf~) throw catch(:ambiguous) { begin raise rescue throw :ambiguou end } end2011 7 19 20
  55. 55. #860 catch/throw (60723bf~) throw catch(:ambiguous) { begin throw raise rescue throw :ambiguou end } end2011 7 19 20
  56. 56. #860 catch/throw (60723bf~) throw vm.cpp:4321: catch(:ambiguous) { VALUE begin throw RoxorVM::ruby_throw(VALUE tag,VALUE value) raise { rescue ... throw :ambiguou // end must pop the current VM exception in case we are in a rescue handler, We // since we are going to unwind the stack. } end if (current_exception() != Qnil) { pop_current_exception(); } ...2011 7 19 20
  57. 57. #860 catch/throw ➡ (60723bf)2011 7 19 21
  58. 58. #860 catch/throw ➡ (60723bf) vm.cpp:4318: VALUE RoxorVM::ruby_throw(VALUE tag,VALUE value) { ... rb_vm_catch_t *catch_ptr = iter->second; while (catch_ptr->current_exception != current_exception()) { pop_current_exception(); } ...2011 7 19 21
  59. 59. #860 catch/throw ➡ (60723bf) catch (catch_ptr->current_exception) vm.cpp:4318: VALUE (current_exception()) RoxorVM::ruby_throw(VALUE tag,VALUE value) { ... rb_vm_catch_t *catch_ptr = iter->second; while (catch_ptr->current_exception != current_exception()) { pop_current_exception(); } ...2011 7 19 21
  60. 60. #860 catch/throw begin raise rescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :ok end2011 7 19 22
  61. 61. #860 catch/throw begin A raise rescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :ok end2011 7 19 22
  62. 62. #860 catch/throw begin A raise A rescue catch_ptr->current_exception = current_exception(); catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :ok end2011 7 19 22
  63. 63. #860 catch/throw begin A raise A rescue catch_ptr->current_exception = current_exception(); catch(:ambiguous) { begin B raise rescue begin raise rescue throw :ambiguous end end } p :ok end2011 7 19 22
  64. 64. #860 catch/throw begin A raise A rescue catch_ptr->current_exception = current_exception(); catch(:ambiguous) { begin B raise rescue begin C raise rescue throw :ambiguous end end } p :ok end2011 7 19 22
  65. 65. #860 catch/throw begin A raise A rescue catch_ptr->current_exception = current_exception(); catch(:ambiguous) { begin B raise rescue begin C raise rescue C B A A throw :ambiguous C B end end } p :ok end2011 7 19 22
  66. 66. #860 catch/throw begin A raise A rescue catch_ptr->current_exception = current_exception(); catch(:ambiguous) { begin B raise rescue begin C raise rescue C B A A throw :ambiguous C B end end } p :ok A end2011 7 19 22
  67. 67. #1192 Did not find nested constants. ➡2011 7 19 23
  68. 68. #1192 Did not find nested constants. ➡ module A B = 10 Object.class_eval { B } end2011 7 19 23
  69. 69. #1192 Did not find nested constants. ➡ module A B = 10 Object.class_eval { B } end reduction.rb:3:in `block: uninitialized constant B (NameError) from reduction.rb:1:in `<main>2011 7 19 23
  70. 70. #1192 Did not find nested constants. ➡ module A Object B B = 10 Object.class_eval { B } end reduction.rb:3:in `block: uninitialized constant B (NameError) from reduction.rb:1:in `<main>2011 7 19 23
  71. 71. #1192 6b101bd~2011 7 19 24
  72. 72. #1192 6b101bd~ module A module B CONST = “B’s Const” module ::A p CONST end end end2011 7 19 24
  73. 73. #1192 6b101bd~ module A module B CONST = “B’s Const” module ::A p CONST end end end -e:5:in `block: uninitialized constant A::CONST (NameError)2011 7 19 24
  74. 74. #1192 6b101bd~ module A module B CONST = “B’s Const” module ::A p CONST ::A A::B A end ::A end end -e:5:in `block: uninitialized constant A::CONST (NameError)2011 7 19 24
  75. 75. module_eval( ) module_eval module A module A CONST = "As CONST" CONST = "As CONST" def f def f class_eval <<-EOS class_eval { p CONST p CONST EOS } end end end end class K class K CONST = "Ks CONST" CONST = "Ks CONST" extend A extend A f f end end2011 7 19 25
  76. 76. module_eval( ) module_eval module A module A CONST = "As CONST" CONST = "As CONST" def f def f class_eval <<-EOS class_eval { p CONST p CONST EOS #=> "Ks CONST" } end end end end class K class K CONST = "Ks CONST" CONST = "Ks CONST" extend A extend A f f end end2011 7 19 25
  77. 77. module_eval( ) module_eval module A module A CONST = "As CONST" CONST = "As CONST" def f def f class_eval <<-EOS class_eval { p CONST p CONST EOS #=> "Ks CONST" } #=> "As CONST" end end end end class K class K CONST = "Ks CONST" CONST = "Ks CONST" extend A extend A f f end end2011 7 19 25
  78. 78. module_eval( ) module_eval module A module A CONST = "As CONST" CONST = "As CONST" def f def f class_eval <<-EOS class_eval { p CONST p CONST EOS #=> "Ks CONST" } #=> "As CONST" end K A Object end end CONST end class K class K CONST = "Ks CONST" CONST = "Ks CONST" extend A extend A f f end end2011 7 19 25
  79. 79. module_eval( ) module_eval module A module A CONST = "As CONST" CONST = "As CONST" def f def f class_eval <<-EOS class_eval { p CONST p CONST EOS #=> "Ks CONST" } #=> "As CONST" end K A Object end A Object end CONST end CONST K class K class K CONST = "Ks CONST" CONST = "Ks CONST" extend A extend A f f end end2011 7 19 25
  80. 80. 2011 7 19 26
  81. 81. module A B = 42 end A.class_eval do def self.f pB end end A.f2011 7 19 26
  82. 82. module A B = 42 Ruby 1.9 end 42 A.class_eval do def self.f pB end end A.f2011 7 19 26
  83. 83. module A B = 42 Ruby 1.9 end 42 A.class_eval do def self.f Ruby 1.8.7 -e:8:in `f: uninitialized constant B (NameError) pB end end A.f2011 7 19 26
  84. 84. module A B = 42 y Ruby 1.9 end b 42 def self.f pB R A.class_eval do c u Ruby 1.8.7 -e:8:in `f: uninitialized constant B (NameError) end end A.f2011 7 19 26
  85. 85. # abort when I pressed “About your application’s environment” in welcome page. ➡ Welcome aboard abort2011 7 19 27
  86. 86. # abort when I pressed “About your application’s environment” in welcome page. ➡ Welcome aboard abort2011 7 19 27
  87. 87. # abort when I pressed “About your application’s environment” in welcome page. ➡ Welcome aboard abort2011 7 19 27
  88. 88. # abort when I pressed “About your application’s environment” in welcome page. ➡ Welcome aboard abort Assertion failed: ((b->flags & flags) == flags), function rb_vm_prepare_block, file dispatcher.cpp, line 1406. zsh: abort env VM_DISABLE_RBO=1 macruby -S rails server2011 7 19 27
  89. 89. ...2011 7 19 28
  90. 90. ... MacRuby Rails ...2011 7 19 28
  91. 91. ... MacRuby Rails ... ➡2011 7 19 28
  92. 92. ... MacRuby Rails ... ➡ ➡ @lrz Rails MacRuby 1.02011 7 19 28
  93. 93. RubyConf ... To be continued... <morohoshi@netlab.jp>2011 7 19 29

×