textmatemacruby

How do I get Textmate to use MacRuby?


So, how do I get Textmate to use MacRuby, a branch of 1.9.2, instead of the default Ruby in OSX, 1.8.7?


Solution

  • Been working on this since last night…finally got it to work

    How to Get MacRuby Running on TextMate

    By (johnrubythecat*)

    *reference to john robie, "the cat", thief played by cary grant in To Catch A Thief

    Ruby on OS X is currently 1.8.7 But latest version of Ruby is 1.9.2 (MUCH faster) And MacRuby (much better than RubyCocoa) is built on 1.9.2

    So here are instructions for easily building mac desktop apps using ruby

    INSTALL RVM

    1) install rvm with git

    $ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) http://rvm.beginrescueend.com/
    

    1.2) source command in .bash_profile or .bashrc (so rvm bin can be found):
    source $HOME/.rvm/scripts/rvm

    INSTALL MACRUBY

    2) Use rvm to install MacRuby

    rvm notes # to see available rubies
    rvm install macruby-0.8 # for exmpl
    

    3) then, rvm --default macruby-0.8
    (or at least rvm use macrmacruby-0.8)

    CONFIGURE TEXTMATE

    4) update Textmate bundles with this script, just to make sure you're up to date; see:


    --- #!/usr/bin/env bash
    mkdir -p /Library/Application\ Support/TextMate/
    sudo chown -R $(whoami) /Library/Application\ Support/TextMate
    cd /Library/Application\ Support/TextMate/
    if [[ -d Bundles/.svn ]] ; then
      cd Bundles && svn up
    else
      if [[ -d Bundles ]] ; then
        mv Bundles Bundles.old
      fi
      svn co http://svn.textmate.org/trunk/Bundles
    fi
    exit 0
    

    5) Generate Ruby wrapper wrapper for TextMate
    rvm wrapper macruby-0.8 textmate

    wrapper is in $HOME/.rvm/bin; it's called textmate_ruby

    6) go to shell variables in TextMate preferences and set TM_RUBY to
    /Users/homedirname/.rvm/bin/textmate_ruby

    that should do it

    RUN YOUR APP

    7) this script ran great —opens a Cocoa window

    framework 'AppKit'
    class AppDelegate
      def applicationDidFinishLaunching(notification)
        voice_type = "com.apple.speech.synthesis.voice.GoodNews"
        @voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type)
      end
    
      def windowWillClose(notification)
        puts "Bye!"
        exit
      end
    
      def say_hello(sender)
        @voice.startSpeakingString("Hello World!")
        puts "Hello World!"
      end
    end
    
    app = NSApplication.sharedApplication
    app.delegate = AppDelegate.new
    
    window = NSWindow.alloc.initWithContentRect([200, 300, 300, 100],
      styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask,
      backing:NSBackingStoreBuffered, 
      defer:false)
    window.title      = 'MacRuby: The Definitive Guide'
    window.level      =  NSModalPanelWindowLevel
    window.delegate   = app.delegate
    button = NSButton.alloc.initWithFrame([80, 10, 120, 80])
    button.bezelStyle = 4
    button.title      = 'Hello World!'
    button.target     = app.delegate
    button.action     = 'say_hello:'
    window.contentView.addSubview(button)
    window.display
    window.orderFrontRegardless
    app.run
    

    And here is a video discussing how to integrate MacRuby with XCode.

    http://thinkcode.tv/catalog/introduction-macruby/

    It's 8.99, but I am recommending something I purchased myself. It's MacRuby is out of date (0.6), but it shows the nuts and bolts of using MacRuby in XCode, including setting up the XIB and making connections, creating the application delegate, setting up Textmate as your external editor.

    Quite useful. Recommended.