Updating Vim on OS X Leopard

7 09 2008

I recently tried to get vim up to version 7.2 on leopard (so that i could get vimball working and install plugins). In the end I settled for using the copy of vim that comes with MacVim and setting up an alias:

alias vim='/Users/logaan/Downloads/MacVim-7_2-stable-1_2\ 2/MacVim.app/Contents/MacOS/Vim'

But before I went to this extreme I tried:

  • Port: The files downloaded didn’t match the checksum.
  • Fink: The version was old but installed properly. Then didn’t work.
  • Manual Compile: Didn’t setup the right paths for plugins, etc.

If you want to do it my way grab the latest version of MacVim from http://code.google.com/p/macvim/ install, then right click on MacVim.app and show contents. Navigate into the MacOS folder and you should see ‘Vim’. Open up ~/.bash_profile in your favorite text editor and type alias vim='' then drag the ‘Vim’ application between the quotes. It should insert the full path to the app.

It’s not pretty, but it works.

Eager to please annonymous objects

6 09 2008

I’ve been doing a lot of unit testing recently, and often find myself wishing that my mock objects actually had a state. So I could push a dumb object into the system and have a look at it when it comes out, without needing to tightly couple the stubbed methods on it to the implimentation. So I’ve written up a little method that’ll help you do exactly that. It allows for javascript style annonymous objects. As soon as you try to write to an attribute or read from one the getters and setters for that attribute are created.

def annon
  # Create a new blank, basic object
  annonymous_object = Object.new

  # If a attribute is called on this object that doesn't exist
  # we want to fake it
  def annonymous_object.method_missing name, *args
    # Figure out the base name of the attribute
    method_name = name.to_s[/[^=]*/]

    # Define the getter and setter
    self.instance_eval <<-METHODS
      def #{method_name}= value
        @#{method_name} = value
      def #{method_name}

    # Call the attribute again
    send name, *args

  # Now that we've created our annonymous object
  # we'll pass it to the block. Here attributes and
  # default values to be added to the object.
  yield annonymous_object if block_given?

  # Finally return the object we've built