Repository navigation
Expand file tree
/
Copy pathfile.try-samples.html
More file actions
160 lines (113 loc) · 5.7 KB
/
Copy pathfile.try-samples.html
File metadata and controls
160 lines (113 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>
File: Try Samples
— RubyCocoa Documentation
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
hasFrames = window.top.frames.main ? true : false;
relpath = '';
framesUrl = "frames.html#!file.try-samples.html";
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<div id="header">
<div id="menu">
<a href="_index.html">Index</a> »
<span class="title">File: Try Samples</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="class_list.html">
Class List
</a>
<a class="full_list_link" id="method_list_link"
href="method_list.html">
Method List
</a>
<a class="full_list_link" id="file_list_link"
href="file_list.html">
File List
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><div id='filecontents'>
<h1 id="label-Try+Samples">Try Samples</h1>
<p>Let's try scripts and applications of samples.</p>
<h2 id="label-RubyCocoa+Application">RubyCocoa Application</h2>
<p>First, try to execute a RubyCocoa application which has already been built.
In Finder, open '/Developer/Examples/RubyCocoa' folder and
double-click SimpleApp. Or type following on command line:</p>
<pre class="code ruby"><code class="ruby">% cd /Developer/Examples/RubyCocoa
% open SimpleApp.app</code></pre>
<h2 id="label-on+command+line+-28Terminal-29">on command line (Terminal)</h2>
<p>You can write a script for command line with RubyCocoa. Now, let's try
to execute a simple script in sample directory.</p>
<pre class="code ruby"><code class="ruby">% cd /Developer/Examples/RubyCocoa
% ruby fontnames.rb # fontname print to stdout.
% ruby sndplay.rb # system sounds play in order.
% ruby sndplay2.rb # system sounds play in order with short interval.</code></pre>
<p>For Mac OS X 10.2 or later users, furthermore:</p>
<pre class="code ruby"><code class="ruby">% echo Hello World | ruby speak.rb
% head -5 speak_me.txt | ruby speak.rb</code></pre>
<p>This will be interesting. When you execute speak.rb without arguments, the
Mac will read all the text you type until 'control-D' is input.
This script uses the AppleScript (and AppleEvent) interface which has been
implemented since Mac OS X 10.2.</p>
<p>Next, try scripts with windowing.</p>
<pre class="code ruby"><code class="ruby">$ ruby HelloWorld.rb # window and buttons
$ ruby TransparentHello.rb # transparency!
$ (cd Hakoiri-Musume && ruby rb_main.rb ) # puzzle game</code></pre>
<h2 id="label-Build+a+Makefile-based+RubyCocoa+application">Build a Makefile-based RubyCocoa application</h2>
<p>The next example is Makefile-based. Type this to build:</p>
<pre class="code ruby"><code class="ruby"><span class='tstring'><span class='tstring_beg'>% </span><span class='tstring_content'>cd</span><span class='tstring_end'> </span></span><span class='op'>/</span><span class='const'>Developer</span><span class='op'>/</span><span class='const'>Examples</span><span class='op'>/</span><span class='const'>RubyCocoa</span><span class='op'>/</span><span class='const'>Hakoiri</span><span class='op'>-</span><span class='const'>Musume</span>
<span class='tstring'><span class='tstring_beg'>% </span><span class='tstring_end'>make</span></span></code></pre>
<p>Now launch the application:</p>
<pre class="code ruby"><code class="ruby">% open CocoHako.app</code></pre>
<p>or double-click 'CocoHako' in the Finder.</p>
<h2 id="label-Build+a+Xcode-based+RubyCocoa+application">Build a Xcode-based RubyCocoa application</h2>
<p>The next example is Xcode-based. Type this to build it:</p>
<pre class="code ruby"><code class="ruby">% cd /Developer/Examples/RubyCocoa/simpleapp
% xcodebuild
% open build/SimpleApp.app</code></pre>
<p>You can build and run the application in Xcode, too. Launch the
application:</p>
<h2 id="label-Next...">Next…</h2>
<p>There are various other samples. Please read and try them. Have fun!</p>
<h2 id="label-Supplement">Supplement</h2>
<ul><li>
<p>HelloWorld.rb is a sample script for <a
href=":http://pyobjc.sf.net/">PyObjc</a> that was translated from Python
into Ruby.</p>
</li><li>
<p>TransparentHello.rb appears in the article of <a
href="http://www.ddj.com/articles/2002/0205/">'Dr. Dobbs Journal, May
2002'</a> written by Chris Thomas.</p>
</li><li>
<p>RubyRaiseMan and RubyTypingTutor is a tutorial application in <a
href="http://www.amazon.com/exec/obidos/tg/detail/-/0201726831">'Mac OS X
Cocoa Programming'</a> that was translated from Objective-C into Ruby.</p>
</li><li>
<p>MyViewer is a sample in Japanese book <a
href="http://www.amazon.co.jp/exec/obidos/ASIN/4877780688">'Guide of Mac OS
X Programming - Objective-C'</a> that was translated from Objective-C into
Ruby.</p>
</li></ul>
</div></div>
<div id="footer">
Generated on Sun May 31 11:56:30 2015 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.2.2).
</div>
</body>
</html>