Skip to content

Instantly share code, notes, and snippets.

@kch
Created May 2, 2010 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kch/387246 to your computer and use it in GitHub Desktop.
Save kch/387246 to your computer and use it in GitHub Desktop.
A more idiomatic rb_main for MacRuby applications
# Loading the Cocoa framework. If you need to load more frameworks, you can do that here too.
framework 'Cocoa'
# Loading all the Ruby project files.
[__FILE__].concat(Dir[File.join(NSBundle.mainBundle.resourcePath.fileSystemRepresentation, '*.{rb,rbo}')])
.map { |path| File.basename(path, File.extname(path)) }.uniq[1..-1]
.each { |name| require(name) }
# Starting the Cocoa main loop.
NSApplicationMain(0, nil)
@kch
Copy link
Author

kch commented May 2, 2010

Do check all the versions and the commit logs for the whys and wherefores;

kch$ git log --oneline --reverse -3
25197a5 step 1: get rid of the silly nesting and conditionals
f873413 step 2: require won't reload a file that's already been required, so
                there's no need to remove self from the require list
0e5d27d step 3: at this point we might as well do away with the variables since
                we don't need to refer back to any of them. FP FTW.

@kch
Copy link
Author

kch commented Oct 10, 2010

It seems I was silly in step 2, so, new commit:

While "require won't reload a file that's already been required", rb_main is never required, it's the main file, hence not in $", so I'm cleverly ditching rb_main from the require list again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment