「Ruby」の版間の差分
提供: MacWiki
(→MacRuby) |
|||
行71: | 行71: | ||
[http://www.macruby.org/ MacRubyホームサイト] | [http://www.macruby.org/ MacRubyホームサイト] | ||
− | + | * コンパイルもサポート(macrubycコマンド): MacOSX上のネイティブコード生成(MacRuby 0.5 beta 1 以降) | |
− | * MacOSX上のネイティブコード生成(MacRuby 0.5 beta 1 以降) | + | |
動作例 | 動作例 | ||
行85: | 行84: | ||
Successfully installed hotcocoa-0.6.0 | Successfully installed hotcocoa-0.6.0 | ||
1 gem installed | 1 gem installed | ||
+ | |||
+ | |||
+ | ==== サンプル ==== | ||
+ | *エイリアスファイルを,それと同等のシンボリックリンクへ変更するスクリプト(エイリアスファイルの方は捨てる): | ||
+ | #!/usr/bin/env macruby | ||
+ | # コマンドの引数に「エイリアスファイル」を指定 | ||
+ | framework 'Foundation' | ||
+ | begin | ||
+ | raise if !File.exists?(file = ARGV[0]) | ||
+ | raise if `GetFileInfo -aA #{file}`.chomp != "1" | ||
+ | a = NSURL.fileURLWithPath(file) | ||
+ | b = NSURL.bookmarkDataWithContentsOfURL(a, error:nil) | ||
+ | options = NSURLBookmarkResolutionWithoutUI | NSURLBookmarkResolutionWithoutMounting | ||
+ | c = NSURL.URLByResolvingBookmarkData(b, options:options, relativeToURL:nil, bookmarkDataIsStale:nil, error:nil) | ||
+ | origPath = c.path | ||
+ | puts "alias file removed: "+ file | ||
+ | system("rm " + file) | ||
+ | system("ln -s " + origPath + " " + file) | ||
+ | system("ls -ld " + file) | ||
+ | rescue | ||
+ | end | ||
=== モジュールのディレクトリ === | === モジュールのディレクトリ === |
2013年2月8日 (金) 18:35時点における版
目次
Ruby とは?
スクリプト言語の1つ。(Mac OS X に標準搭載されている。)
- プログラミングの入門に薦める人も多い。
- 詳しくは下記をなどを参照して下さい。
Mac OS X 特有の情報
gcc-4.2
Ruby 1.8 および gem install などの際に gcc-4.2を必要とする(llvm-gcc-4.2ではなく)。
- MacOSX 10.7 では、gcc-4.2 を入手しなければならない。(MacOSX 10.6 では、Developer開発一式をインストールすれば、最初から入っている)
gem install の例
$ ls -l `which cc` lrwxr-xr-x 1 root wheel 16 5 24 18:38 /usr/bin/cc -> /usr/bin/gcc-4.2 $ sudo -E gem install hpricot Building native extensions. This could take a while... Successfully installed hpricot-0.8.6 1 gem installed $ gem list
バグ
- Tiger (PPC) のrubyは、適切でないオプションで build されていてmigemoやrails等がうまく動作しないようです。
- SocketError発生(MacOSX 10.5.7 で確認)(`initialize': getaddrinfo: nodename nor servname provided, or not known (SocketError) ..)
Ruby on Rails
従って、Ruby on Rails を Mac OS X Tigerで動作させるためには、 ruby を別途インストールする必要があります。
- http://www.goodpic.com/mt/archives2/2005/09/ruby_on_rails_m_1.html
- http://weblog.rubyonrails.com/archives/2005/04/30/fixing-ruby-on-os-x-tiger/
- http://wiki.rubyonrails.com/rails/pages/HowtoInstallOnOSXTiger
開発環境としては、Locomotive が有名です。
上記の情報は古い可能性があります。 2006-06-08 時点の情報が Apple のサイトに掲載されています。
なお、Mac OS X 10.5 (Leopard) には、Ruby on Rails が標準で搭載される予定だそうです。
Ruby/Tk
Mac OS X Tigerで動作するRuby/Tkは、Tcl/Tk Aquaがベースになってるので、ウィジェットの外観はAqua風になります。
RubyCocoa
RubyCocoa は、Cocoa ベースのソフトウェアを Ruby で記述できるようにしたフレームワークです。 WWDC06 において、Mac OS X 10.5 (Leopard) にバンドルされる予定であることが公表されました。
同様のソフトウェアとして、Python バインディングである PyObjC や Perl バインディングである CamelBones があります。⇒Perl
MacRuby
- コンパイルもサポート(macrubycコマンド): MacOSX上のネイティブコード生成(MacRuby 0.5 beta 1 以降)
動作例
$ macirb --simple-prompt >> framework 'AppKit' >> voice = NSSpeechSynthesizer.alloc.initWithVoice(nil) >> voice.startSpeakingString("Hello, world.")
hotcocoaもインストールするには
$ sudo -E macgem install hotcocoa Password: Successfully installed hotcocoa-0.6.0 1 gem installed
サンプル
- エイリアスファイルを,それと同等のシンボリックリンクへ変更するスクリプト(エイリアスファイルの方は捨てる):
#!/usr/bin/env macruby # コマンドの引数に「エイリアスファイル」を指定 framework 'Foundation' begin raise if !File.exists?(file = ARGV[0]) raise if `GetFileInfo -aA #{file}`.chomp != "1" a = NSURL.fileURLWithPath(file) b = NSURL.bookmarkDataWithContentsOfURL(a, error:nil) options = NSURLBookmarkResolutionWithoutUI | NSURLBookmarkResolutionWithoutMounting c = NSURL.URLByResolvingBookmarkData(b, options:options, relativeToURL:nil, bookmarkDataIsStale:nil, error:nil) origPath = c.path puts "alias file removed: "+ file system("rm " + file) system("ln -s " + origPath + " " + file) system("ls -ld " + file) rescue end
モジュールのディレクトリ
/Library/Ruby/Site/
- MacOSX では site_ruby という名前ではないとのこと.http://d.hatena.ne.jp/keigoi/20081203/1228311997