Importer v0.2

August 22nd, 2009

Danlucraft pointed something out the other day: Why would Importer require that you use a hash? And of course he was right. So after a little review: Importer, second iteration:

module Importer

  module ClassMethods
    def importer(package, classes)
        classes.each do |item|
          path = package + "." + item
          import path
        end
    end
  end

  def self.included(receiver)
    receiver.extend ClassMethods
  end

end

This will remove the pesky hash notation:

require 'importer'

class Banzaiii
  include Importer
  importer 'org.eclipse.swt.widgets', \
      %w{Display, Shell, Button, Canvas}
  importer 'org.eclipse.swt', ['SWT']

  def build
    puts SWT::BOLD | SWT::ITALIC 
  end
end
Maybe this will evolve into something that enables you to do the follwing:
class Widgets
  include Importer
  importer 'org.eclipse.swt.widgets.*'
end

# and thus
canvas = Widgets::Canvas.new

Which is exactly what is currently missing from jruby…

Leave a Reply

You can use Textile markup in your comments!