Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ruby on Windows ( 2011)


Published on

Small intro about using Ruby on Windows.

Published in: Technology
  • Be the first to comment

Ruby on Windows ( 2011)

  1. 1. RUBY ON WINDOWS Up and RuningSaturday, August 27, 11 1
  2. 2. WHO AM I?Saturday, August 27, 11 2
  3. 3. About me 張銘軒 (Mason Chang) Was a hardware engineer Love software and programming Start using Ruby since late 2009 Twitter: @changmason (I don’t tweet though) Email: changmason@gmail.comSaturday, August 27, 11 3
  4. 4. WHY (ON WINDOWS)?Saturday, August 27, 11 4
  5. 5. You are more familiar with Windows environments.Picture courtesy of yum9me (CC) BY-NC-ND 2.0, August 27, 11 5
  6. 6. You don’t want to fight against existing tools and workflows inside your company.Picture courtesy of erix (CC) BY 2.0, August 27, 11 6
  7. 7. Broader user base, your target users are on Windows.Picture courtesy of opacity (CC) BY-NC-ND 2.0, August 27, 11 7
  8. 8. WHAT RUBY? ... BECAUSESaturday, August 27, 11 8
  9. 9. Many Rubies (which on Win?) MRI JRuby IronRuby Rubinius MacRuby MagLev ◎ ◎ ◎ ▵ ✕ ✕ ◎ => Yes. ✕ => No. ▵ => Maybe. (planned to support Windows in the near future)Saturday, August 27, 11 9
  10. 10. BUT, Windows users don’t like to compile code!!!Picture courtesy of TahoeSunsets (CC) BY-NC-SA 2.0, August 27, 11 10
  11. 11. Ruby Installer Compiled executables under MinGW32 dev environment Both newest Ruby 1.8.7p352 and 1.9.2p290 are availableSaturday, August 27, 11 11
  12. 12. JRuby Installer Require JRE (or JDK if you want to compile .rb into .class) Ruby 1.8 compatible and Ruby 1.9 supportedSaturday, August 27, 11 12
  13. 13. Rails Installer All in one package, including MRI Ruby, Rails, Git and DevKitSaturday, August 27, 11 13
  14. 14. rvm => No, pik => Yes Very similar to rvm, it helps you to install, manage, and switch among all available Rubies on Windows. There are two ways to install pik: 1. If you already have a Ruby installed: gem install pik pik_install c:bin 2.otherwise, use pik installer:, August 27, 11 14
  15. 15. pik help commandsSaturday, August 27, 11 15
  16. 16. Other Dev Tools Version control: msysgit: git-bash: Provide a *nix-like CLI with colors on Windows. Text editors: Notepad++: (Freeware) E-texteditor: (Textmate clone)Saturday, August 27, 11 16
  17. 17. HOW TO ?Saturday, August 27, 11 17
  18. 18. How to code? EOL(end of line): To share your code with the community, please convert EOL from Windows format(CRLF) to UNIX format(LF) in your source files. (You text editors can do this for you, check it!!) Pathname: Although Ruby, on Windows, can automatically translate in between “/” and “” of a file path, it is recommended that you use “pathname” to handle a complex file path which is got from the user. (There may be spaces and Chinese characters.)Saturday, August 27, 11 18
  19. 19. How to install gems? “gem install xxx” will automatically detect your platform and install the right gem for you. For JRuby, please use “jruby -S gem install xxx” instead. You can also manually download and install the gems that correspond to your platform if “gem install xxx” fail to detect the right gems for you.Saturday, August 27, 11 19
  20. 20. How about gem compatibility? Most gems written in pure Ruby or shipped with precompiled C-extension work out of the box on Windows: sinatra, nokogiri Some gems with native C-extension may need a few tweaks and compilation(DevKit is your friend): mysql2 Still there are very few gems that will hardly work on Windows because they are designed for POSIX OS: unicornSaturday, August 27, 11 20
  21. 21. How to do Windows automation (use WIN32OLE)? Operate Windows applications just like operate Ruby objects, (no need to write any VB script): InternetExplorer, Excel, Word, PowerPoint... Reflection support through methods with prefix ole_*: :ole_methods, :ole_type, :ole_method_help OLE object’s OLE methods are case insensitive: obj.visible is the same as object.ViSiBlE Please refer to MSDN for API:, August 27, 11 21
  22. 22. WIN32OLE - example, August 27, 11 22
  23. 23. How to program GUI? Several libraries are available: FoxRuby, WxRuby, Shoes, Bowline However, these gems are not under regular maintenance GUI programming with Swing in JRuby is a good solutionSaturday, August 27, 11 23
  24. 24. Swing GUI - example(p1), August 27, 11 24
  25. 25. Swing GUI - example(p2) import Java classes to current Ruby namespace Ruby class can inherit Java class call Java’s constructor setter in Java style event handling by a Ruby block tell the swing worker to run in background setter in Ruby styleSaturday, August 27, 11 25
  26. 26. Swing GUI - example(p3) Although JRuby runtime can call Java methods in camelCaseStyle or in snake_case_style, this doInBackground method is invoked by Java in the background thread actually. So we MUST name it in Java way.Saturday, August 27, 11 26
  27. 27. How about packaging your programs? In Ruby use OCRA (One Click Ruby Application): Package all your source files with the Ruby interpreter and required gems into one .exe file. In JRuby use rawr or Warbler: Same as above, but they can also help you to compile your .rb files into .class files. The output can be a standalone .jar, .war or .exe file.Saturday, August 27, 11 27
  28. 28. CONCLUSIONSaturday, August 27, 11 28
  29. 29. (J)Ruby on Windows is already good enough to learn and play with. We can get more Windows users to join this community. Rubys concise syntax and direct access to OLE objects make it a powerful productivity tool on Windows. Stick to JRuby/Java technologies if you really care about cross- platform compatibilities of your programs. Eventually, you would buy a Mac or setup a Linux machine if developing (Rails) on Windows really hurts your productivity.Saturday, August 27, 11 29
  30. 30. Q&ASaturday, August 27, 11 30