3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RubyからCocoaを使ってみる

Posted at

RubyからCocoa(macOSのAPI)を使ってみる。
以前、RubyCocoaというものがあった。今は動かなくなっているようだ。
近いものとして、cocoaというgem packageがある。
https://github.com/patrickhno/cocoa/

インストールする。

% gem install cocoa
Successfully installed cocoa-0.1.6
Parsing documentation for cocoa-0.1.6
Done installing documentation for cocoa after 3 seconds
1 gem installed

サンプルプログラムを実行してみる。

test1.rb
require 'cocoa'
Cocoa::NSAutoreleasePool.new
app = Cocoa::NSApplication.sharedApplication
app.setActivationPolicy Cocoa::NSApplicationActivationPolicyRegular
app.activateIgnoringOtherApps true
alert = Cocoa::NSAlert.alloc.init.autorelease
alert.setMessageText "Hello world!"
alert.runModal

% ruby test1.rb
/usr/local/lib/ruby/gems/2.7.0/gems/cocoa-0.1.6/lib/cocoa/objc/method_def.rb:154: warning: constant ::Fixnum is deprecated
/usr/local/lib/ruby/gems/2.7.0/gems/cocoa-0.1.6/lib/cocoa/objc/method_def.rb:154: warning: constant ::Fixnum is deprecated
/usr/local/lib/ruby/gems/2.7.0/gems/cocoa-0.1.6/lib/cocoa/objc/method_def.rb:154: warning: constant ::Bignum is deprecated

無事実行されるのだが、warningが気になるな。今度、修正してみよう。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?