MobileRuby:使用Ruby開發(fā)iOS應(yīng)用的輕量級框架
該項目由Yuichiro MASUI發(fā)起,此人為Appcelerator工作。Appcelerator是一家提供移動平臺開發(fā)框架的公司,其Titanium開發(fā)框架允許開發(fā)者使用自己熟悉的語言來開發(fā)移動應(yīng)用。
MobiRuby基于mruby(輕量級的Ruby語言實現(xiàn),可使用解釋模式運行Ruby代碼并在虛擬機中執(zhí)行)構(gòu)建。Yuichiro MASUI希望通過該框架,使Ruby能夠替代Objective-C/C/Java語言來開發(fā)移動應(yīng)用,就像Lua或Mono一樣。
目前,該項目只有一個代碼示例和截圖,Yuichiro稱,***版本將在未來幾個月內(nèi)發(fā)布,將基于Apache 2.0許可協(xié)議。
MobiRuby示例:
Ruby代碼:
- # UIAlertView demo
- def _S(str)
- NSString._stringWithUTF8String(str)
- end
- class MyAlertView < Mobi::Cocoa::UIAlertView
- define :void, :didPresentAlertView, :id do
- p "MyAlertView::didPresentAlertView"
- end
- define :void, :alertView, :id, :clickedButtonAtIndex, :int do |me, index|
- if index == 1
- app = UIApplication._sharedApplication
- url = NSURL._URLWithString(_S("http://mobiruby.org"))
- app._openURL url
- end
- end
- end
- alert = MyAlertView._alloc.
- _initWithTitle _S("Hello"),
- :message, _S("I'm MobiRuby"),
- :delegate, nil,
- :cancelButtonTitle, _S("I know!"),
- :otherButtonTitles, _S("What's?"), nil
運行結(jié)果:
【編輯推薦】