Remove [Courses] from lesson names/post subjects
[mbox2moodle.git] / source / ruby
blob49bf177901bdb45845c1ea8a7b453dd529d8d2df
1 From laurel.fan@gmail.com  Tue Nov  8 04:41:12 2005
2 Return-Path: <laurel.fan@gmail.com>
3 X-Original-To: courses@linuxchix.org
4 Delivered-To: courses@linuxchix.org
5 Received: from localhost (localhost [127.0.0.1])
6         by www.linuxchix.org (Postfix) with ESMTP id C3787273208
7         for <courses@linuxchix.org>; Tue,  8 Nov 2005 04:41:12 +1100 (EST)
8 Received: from www.linuxchix.org ([127.0.0.1])
9         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
10         id 05342-08 for <courses@linuxchix.org>;
11         Tue, 8 Nov 2005 04:41:12 +1100 (EST)
12 X-Greylist: delayed 430 seconds by postgrey-1.21 at nest;
13         Tue, 08 Nov 2005 04:41:11 EST
14 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.198])
15         by www.linuxchix.org (Postfix) with ESMTP id 012DB2731AF
16         for <courses@linuxchix.org>; Tue,  8 Nov 2005 04:41:11 +1100 (EST)
17 Received: by xproxy.gmail.com with SMTP id t13so439472wxc
18         for <courses@linuxchix.org>; Mon, 07 Nov 2005 09:41:10 -0800 (PST)
19 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
20         h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
21         b=g9P+yTRFvq28iywG6f4F/FQp1H72LKcj6SjDW+mz5u+JlWgRPBhCKkAq6bbsU1wDGrSSQclJWLv1wW3l9OSMsN/PFohYmtNEmV6m+uCVJtj7lPpA8HHDp8hqSK7jdGhpAD3XUBoMO6rAVgdXNAIctZIhf99EkDcqYygFm6OT1MM=
22 Received: by 10.70.100.20 with SMTP id x20mr4467482wxb;
23         Mon, 07 Nov 2005 09:33:58 -0800 (PST)
24 Received: by 10.70.94.2 with HTTP; Mon, 7 Nov 2005 09:33:58 -0800 (PST)
25 Message-ID: <8b1e030f0511070933x1425afddpc08353d0de2f883a@mail.gmail.com>
26 Date: Mon, 7 Nov 2005 09:33:58 -0800
27 From: Laurel Fan <laurel.fan@gmail.com>
28 To: Techtalk <techtalk@linuxchix.org>, programming@linuxchix.org,
29         courses@linuxchix.org
30 MIME-Version: 1.0
31 Content-Type: text/plain; charset=ISO-8859-1
32 Content-Transfer-Encoding: quoted-printable
33 Content-Disposition: inline
34 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
35 X-Topics: Introduction to Ruby
36 Subject: [Courses] [Ruby] Ruby course, Announcement
37 X-BeenThere: courses@linuxchix.org
38 X-Mailman-Version: 2.1.5
39 Precedence: list
40 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
41 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
42         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
43 List-Archive: <http://linuxchix.org/pipermail/courses>
44 List-Post: <mailto:courses@linuxchix.org>
45 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
46 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
47         <mailto:courses-request@linuxchix.org?subject=subscribe>
48 X-List-Received-Date: Mon, 07 Nov 2005 17:41:13 -0000
49 Content-Length: 2958
50 Lines: 87
52 Here's the "official" announcement of the Ruby course!  Thanks for
53 everyone's patience, and I hope we can have some fun with this!=20
54 Please join the courses mailing list and subscribe to the ruby topic
55 to participate.  Lesson 0 will be sent out today, so if you subscribe
56 today and miss it, please check the archives.
58 Audience
59 --------
61 This course is designed for both people completely new to programming
62 and for experienced programmers who want to learn another language
63 (FWIW, Ruby was approximately my 8th language, and about the 5th that
64 I've actually used "for real").
66 Format
67 ------
69 This will be a discussion group format course.  I'll schedule certain
70 chapters of the book to be discussed at specified times, and make a
71 set of questions and programming problems to start off the discussion,
72 but I won't provide the content (that comes from the book).  I'll make
73 a commitment to help make sure everyone's questions are answered, but
74 all participants should feel free to answer questions and start
75 discussions: the course will be even more fun if we all bring our
76 experience and expertise.
78 Material
79 --------
81 We'll only be covering Ruby the language in this course.  You'll know
82 the language well enough to explore advanced topics such as Rails,
83 other web stuff, GUI programming, etc.  I'll be going on a 3 week
84 vacation at the end of December, so that will be a perfect time for
85 someone else to step up and do a mini-course on a more specific topic
86 (if that's something that you're interested leading, please keep it in
87 mind!).
89 Book
90 ----
92 The book we're using is 'Programming Ruby', by Dave Thomas et al.  The
93 2nd edition is preferred, and may be purchased at your online/offline
94 bookstore of choice, or from the authors at
95 http://pragmaticprogrammer.com/titles/ruby/index.html. If you do not
96 wish to purchase the book, the 1st edition is online (for free) at
97 http://www.rubycentral.com/book/.  The 1st edition is sufficient for
98 this course, if you supplement it with the most recent online
99 documentation.
102 Lesson Plan
103 -----------
105 Lessons are deliberately large and spaced far apart to allow for
106 flexibility around everyone's holiday plans.  The dates are when the
107 discussion questions and programming problems will be posted; don't
108 feel required to have the reading finished by then.  Also, don't feel
109 required to only discuss topics covered in the latest readings.
111 Nov 7: Lesson 0
112     Downloading and Installing
113     General References
115 Nov 14:  Lesson 1:
116     1. Getting Started (Foreword/Preface/Roadmap in 1ed)
117     2. Ruby.new
118     3. Classes, Objects, and Variables
120 Nov 28: Lesson 2:
121     4. Containers, Blocks, and Iterators
122     5. Standard Types
123     6. More About Methods
125 Dec 12: Lesson 3:
126     7. Expressions
127     8. Modules
128     9. Exceptions, Catch, and Throw
130 Dec 19: Lesson 4:
131     10. Basic Input and Output
132     11. Threads and Processes
133     12. Unit Testing
134     13. When Trouble Strikes
137 Laurel Fan
138 http://dreadnought.gorgorg.org
140 From laurel.fan@gmail.com  Tue Nov  8 12:37:05 2005
141 Return-Path: <laurel.fan@gmail.com>
142 X-Original-To: courses@linuxchix.org
143 Delivered-To: courses@linuxchix.org
144 Received: from localhost (localhost [127.0.0.1])
145         by www.linuxchix.org (Postfix) with ESMTP id 2BD2C273208
146         for <courses@linuxchix.org>; Tue,  8 Nov 2005 12:37:05 +1100 (EST)
147 Received: from www.linuxchix.org ([127.0.0.1])
148         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
149         id 08093-08 for <courses@linuxchix.org>;
150         Tue, 8 Nov 2005 12:37:05 +1100 (EST)
151 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.203])
152         by www.linuxchix.org (Postfix) with ESMTP id 1321E273206
153         for <courses@linuxchix.org>; Tue,  8 Nov 2005 12:37:03 +1100 (EST)
154 Received: by xproxy.gmail.com with SMTP id s9so533131wxc
155         for <courses@linuxchix.org>; Mon, 07 Nov 2005 17:37:01 -0800 (PST)
156 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
157         h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
158         b=TOT+NZyajLu6lL8BxgSyjn6EyDxtJmKcxnZ3f/047lv4ZfsC31ZSoP57SYqykqbpGbn9uOZbPzqIz231lIj+r2NFUOBgLkb7ojQAiglbxlKuIkOoTHb0gsH4gBrLUArto1zE6XEAWlAENRd4MAXi/xsdziYyEGXYpmRhCNQEbMM=
159 Received: by 10.70.116.18 with SMTP id o18mr5784833wxc;
160         Mon, 07 Nov 2005 17:30:16 -0800 (PST)
161 Received: by 10.70.94.2 with HTTP; Mon, 7 Nov 2005 17:30:16 -0800 (PST)
162 Message-ID: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
163 Date: Mon, 7 Nov 2005 17:30:16 -0800
164 From: Laurel Fan <laurel.fan@gmail.com>
165 To: courses@linuxchix.org
166 MIME-Version: 1.0
167 Content-Type: text/plain; charset=ISO-8859-1
168 Content-Transfer-Encoding: quoted-printable
169 Content-Disposition: inline
170 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
171 X-Topics: Introduction to Ruby
172 Subject: [Courses] [Ruby] Lesson 0: Installing, References,
173         and your first homework assignment
174 X-BeenThere: courses@linuxchix.org
175 X-Mailman-Version: 2.1.5
176 Precedence: list
177 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
178 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
179         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
180 List-Archive: <http://linuxchix.org/pipermail/courses>
181 List-Post: <mailto:courses@linuxchix.org>
182 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
183 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
184         <mailto:courses-request@linuxchix.org?subject=subscribe>
185 X-List-Received-Date: Tue, 08 Nov 2005 01:37:05 -0000
186 Content-Length: 3495
187 Lines: 108
189 =3D Lesson 0: Installing and Documentation References
191 =3D=3D Installing
193 =3D=3D=3D Linux
195 Any modern Linux distribution has ruby package(s).  It might even
196 already be installed.  (To check, try 'ruby --version' in a shell). If
197 you don't have it, install it with the appropriate package management
198 system.  The exact procedure will vary for your distribution.  To
199 start with, for yum-based systems, try::
201 # yum install ruby
203 and for apt-get based systems:
205 # apt-get install ruby
207 If you need more help, ask on the list.
209 In both Fedora and Debian, irb (interactive ruby, which has a better
210 interactive UI than the plain old ruby command) and ri (documentation
211 tool) are separate packages (called irb and ri).  You'll probably want
212 to install those as well.
214 =3D=3D=3D Windows
216 There's an installer for Windows here:
218 http://rubyinstaller.rubyforge.org/wiki/wiki.pl
220 =3D=3D=3D Mac OS X
222 Tiger (10.4) comes with Ruby installed.  For earlier versions, try
223 this page:
225 http://homepage.mac.com/discord/Ruby/
227 (I found it on a google search and haven't tried it, so if you do, let
228 us know how it goes.)
230 =3D=3D Documentation References
232 There are lots of places to find documentation for Ruby.  Sinc nearly
233 everything you'd search for is an actual word (including 'ruby'
234 itself, of course), it can be hard to google for.
236 If you have the 2nd edition of the book, the API reference that starts
237 in about the middle of the book is great.  With the 1st edition, some
238 of that will be out of date.
240 The canonical source for online documentation is:
242 http://ruby-doc.org/
244 If you have Firefox/Mozilla, there's a fancy sidebar for ruby-doc:
246 http://ruby-doc.org/docbar/
248 If you have the 'ri' commad, you can use that for
249 documentation for libraries that you have installed.  For example:
251 > ri File.new
252 -------------------------------------------------------------- File::new
253      File.new(filename, mode=3D"r")            =3D> file
254      File.new(filename [, mode [, perm]])    =3D> file
255 ------------------------------------------------------------------------
256      Opens the file named by _filename_ according to _mode_ (default is
258 [...]
260 Finally, here is another online ruby book featuring cartoon foxes:
262 http://www.poignantguide.net/ruby/
264 Other websites that may be useful include:
266 RubyForge: http://rubyforge.org
267 Ruby home page (in English): http://ruby-lang.org/en
270 =3D=3D Homework
272 Please 'turn in' your homework on the courses list, using the [Ruby]
273 subject tag, and with a subject that has something about 'lesson 0'
274 and 'homework'.  It's not due by a specific time, but I would
275 recommend starting before the next lesson is posted (Mon Nov 14).
277 First, introduce yourself.  Do you know any other programming
278 languages?  What do you like/not like about them?  Why are you
279 interested in Ruby?  What are some things you'd like to learn to do?
281 Second, find and run any ruby program.  It can be something you wrote,
282 something you downloaded (hint, look on RubyForge), an example you
283 copied out of a book, something a friend wrote for you, etc.
285 Finally, look at the code.  Find a section of about 5-20 lines of
286 code, and try to figure out what it does.  If you figure it out (or
287 just have a good guess), explain it to us.  If not, show us the code
288 and we'll try to explain it.
290 That's it, Lesson 1 (covering Chapters 1-3 of the book, "Getting
291 Started", "Ruby.new", and "Classes, Objects, and Variables") is next
292 week, Mon Nov 14.  See you on the list!
295 Laurel Fan
296 http://dreadnought.gorgorg.org
298 From Mallory.Chua@students.olin.edu  Tue Nov  8 14:51:12 2005
299 Return-Path: <Mallory.Chua@students.olin.edu>
300 X-Original-To: courses@linuxchix.org
301 Delivered-To: courses@linuxchix.org
302 Received: from localhost (localhost [127.0.0.1])
303         by www.linuxchix.org (Postfix) with ESMTP id 5F651273209
304         for <courses@linuxchix.org>; Tue,  8 Nov 2005 14:51:12 +1100 (EST)
305 Received: from www.linuxchix.org ([127.0.0.1])
306         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
307         id 08906-08 for <courses@linuxchix.org>;
308         Tue, 8 Nov 2005 14:51:12 +1100 (EST)
309 X-Greylist: delayed 728 seconds by postgrey-1.21 at nest;
310         Tue, 08 Nov 2005 14:51:09 EST
311 Received: from olinexvs01.olin.edu (unknown [4.21.174.38])
312         by www.linuxchix.org (Postfix) with ESMTP id 01E4F273205
313         for <courses@linuxchix.org>; Tue,  8 Nov 2005 14:51:08 +1100 (EST)
314 Received: from [127.0.0.1] ([10.41.24.179]) by olinexvs01.olin.edu with
315         Microsoft SMTPSVC(6.0.3790.1830); Mon, 7 Nov 2005 22:38:52 -0500
316 Message-ID: <43701DCC.3090802@students.olin.edu>
317 Date: Mon, 07 Nov 2005 22:38:52 -0500
318 From: Mel Chua <mallory.chua@students.olin.edu>
319 User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
320 X-Accept-Language: en-us, en
321 MIME-Version: 1.0
322 To: courses@linuxchix.org
323 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References, and your first
324         homework assignment
325 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
326 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
327 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
328 Content-Transfer-Encoding: 7bit
329 X-OriginalArrivalTime: 08 Nov 2005 03:38:52.0256 (UTC)
330         FILETIME=[F009FE00:01C5E415]
331 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
332 X-Topics: Introduction to Ruby
333 X-BeenThere: courses@linuxchix.org
334 X-Mailman-Version: 2.1.5
335 Precedence: list
336 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
337 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
338         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
339 List-Archive: <http://linuxchix.org/pipermail/courses>
340 List-Post: <mailto:courses@linuxchix.org>
341 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
342 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
343         <mailto:courses-request@linuxchix.org?subject=subscribe>
344 X-List-Received-Date: Tue, 08 Nov 2005 03:51:12 -0000
345 Content-Length: 2569
346 Lines: 62
348 Hi, I'm Mel. This is my first class. I'm an electrical engineering 
349 student at Olin College in Boston, and don't know as much about coding 
350 as my friends seem to believe, but I'm trying to fix that. I was sort of 
351 the token "coder girl" in high school and tend more towards theory than 
352 hacking, and I'm also trying to tip that balance to the other side. I 
353 want to learn how to mess with things and not be afraid of blowing up my 
354 computer, darn it.
356 I've worked with C++, C, Python, and Scheme, but never got too in-depth 
357 with any of them, though I loved Python's 
358 "just-hack-it-together"-ability and the way Scheme makes you think 
359 differently than any other language I've seen. Ruby piqued my interest 
360 because I've heard it's a beautiful yet powerful little language, and 
361 wanted to learn more. I've been meaning to play with Ruby On Rails, so I 
362 figured this might be a good place to start before launching into that.
364 Homework the First - I tried looking at wiki.rb from the Instiki source 
365 code (a wiki written in Ruby - it's spiffy, and I'd like to learn how it 
366 works). Thankfully, it's well-commented and cleanly-written. I still 
367 have no idea what is going on, but here are my guesses.
369 This is code for something called a Word, which is a type of WikiLink. 
370 It's any group of letters that fits the wiki_word_pattern, whatever that 
371 is. If the code finds that the wiki word is escaped, it'll mark the 
372 entire inputted word as escaped; otherwise it marks nothing as escaped 
373 and cranks the entire thing through, hooking it up to a link of the same 
374 name. I can't tell you what individual lines of code do, though.
376 #---------- begin code ---------------
377   # This chunk matches a WikiWord. WikiWords can be escaped
378   # by prepending a '\'. When this is the case, the +escaped_text+
379   # method will return the WikiWord instead of the usual +nil+.
380   # The +page_name+ method returns the matched WikiWord.
381   class Word < WikiLink
383     attr_reader :escaped_text
384    
385     unless defined? WIKI_WORD
386       WIKI_WORD = Regexp.new('(":)?(\\\\)?(' + 
387 WikiWords::WIKI_WORD_PATTERN + ')\b', 0, "utf-8")
388     end
390     def self.pattern
391       WIKI_WORD
392     end
394     def initialize(match_data, content)
395       super
396       @textile_link_suffix, @escape, @page_name = match_data[1..3]
397       if @escape
398         @unmask_mode = :escape
399         @escaped_text = @page_name
400       else
401         @escaped_text = nil
402       end
403       @link_text = WikiWords.separate(@page_name)
404       @unmask_text = (@escaped_text || @content.page_link(@page_name, 
405 @link_text, @link_type))
406     end
408   end
411 From laurel.fan@gmail.com  Sat Nov 12 05:41:52 2005
412 Return-Path: <laurel.fan@gmail.com>
413 X-Original-To: courses@linuxchix.org
414 Delivered-To: courses@linuxchix.org
415 Received: from localhost (localhost [127.0.0.1])
416         by www.linuxchix.org (Postfix) with ESMTP id 5A7F327320E
417         for <courses@linuxchix.org>; Sat, 12 Nov 2005 05:41:52 +1100 (EST)
418 Received: from www.linuxchix.org ([127.0.0.1])
419         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
420         id 07777-09 for <courses@linuxchix.org>;
421         Sat, 12 Nov 2005 05:41:52 +1100 (EST)
422 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.205])
423         by www.linuxchix.org (Postfix) with ESMTP id 15F162731FC
424         for <courses@linuxchix.org>; Sat, 12 Nov 2005 05:41:50 +1100 (EST)
425 Received: by xproxy.gmail.com with SMTP id t13so773143wxc
426         for <courses@linuxchix.org>; Fri, 11 Nov 2005 10:41:45 -0800 (PST)
427 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
428         h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
429         b=WOP6P7z7yi7Gtdu7+IPSDHyEfD2netOLCzLa8CkbG0Kd/0YJ6nylJN81jw47EjL1tURMw4R1pwsdz0oVoFCps3nfqNrHqDwX6kdM2K5OuHh2MLwBUEtSp+yiKXfOkCikC5DBDZdAKdqdLfLxbPQxZQ1rlc+MJRkRGGAl5+nRf+Y=
430 Received: by 10.70.124.8 with SMTP id w8mr2485033wxc;
431         Fri, 11 Nov 2005 10:41:45 -0800 (PST)
432 Received: by 10.70.94.2 with HTTP; Fri, 11 Nov 2005 10:41:45 -0800 (PST)
433 Message-ID: <8b1e030f0511111041vab0e6a9m69203491e668f0b2@mail.gmail.com>
434 Date: Fri, 11 Nov 2005 10:41:45 -0800
435 From: Laurel Fan <laurel.fan@gmail.com>
436 To: Mel Chua <mallory.chua@students.olin.edu>
437 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
438         and your first homework assignment
439 In-Reply-To: <43701DCC.3090802@students.olin.edu>
440 MIME-Version: 1.0
441 Content-Type: text/plain; charset=ISO-8859-1
442 Content-Transfer-Encoding: quoted-printable
443 Content-Disposition: inline
444 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
445         <43701DCC.3090802@students.olin.edu>
446 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
447 X-Topics: Introduction to Ruby
448 Cc: courses@linuxchix.org
449 X-BeenThere: courses@linuxchix.org
450 X-Mailman-Version: 2.1.5
451 Precedence: list
452 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
453 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
454         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
455 List-Archive: <http://linuxchix.org/pipermail/courses>
456 List-Post: <mailto:courses@linuxchix.org>
457 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
458 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
459         <mailto:courses-request@linuxchix.org?subject=subscribe>
460 X-List-Received-Date: Fri, 11 Nov 2005 18:41:52 -0000
461 Content-Length: 4693
462 Lines: 125
464 On 11/7/05, Mel Chua <mallory.chua@students.olin.edu> wrote:
465 > Hi, I'm Mel.
466 [snip]
468 Hi Mel!
470 > Homework the First - I tried looking at wiki.rb from the Instiki source
471 > code (a wiki written in Ruby - it's spiffy, and I'd like to learn how it
472 > works). Thankfully, it's well-commented and cleanly-written. I still
473 > have no idea what is going on, but here are my guesses.
475 > This is code for something called a Word, which is a type of WikiLink.
476 > It's any group of letters that fits the wiki_word_pattern, whatever that
477 > is. If the code finds that the wiki word is escaped, it'll mark the
478 > entire inputted word as escaped; otherwise it marks nothing as escaped
479 > and cranks the entire thing through, hooking it up to a link of the same
480 > name. I can't tell you what individual lines of code do, though.
482 It is a little hard to figure out what just this but does, since it
483 looks like ot uses stuff from things elsewhere in the code.  But I'll
484 do my best to explain what each lines do:
486 > #---------- begin code ---------------
487 >   # This chunk matches a WikiWord. WikiWords can be escaped
488 >   # by prepending a '\'. When this is the case, the +escaped_text+
489 >   # method will return the WikiWord instead of the usual +nil+.
490 >   # The +page_name+ method returns the matched WikiWord.
491 >   class Word < WikiLink
493 Word inherits from WikiLink, which means that a Word can do everything
494 a WikiLink can, and maybe more.  Lesson 1 will talk a bit more about
495 this
497 >     attr_reader :escaped_text
499 This means that Word has an attribute called escaped_text, that you
500 can read, but not write.  So you could say something like
501 print word.escaped_text
502 to get the value of escaped_text, but you could not do
503 word.escaped_text =3D "something else"
505 >     unless defined? WIKI_WORD
506 >       WIKI_WORD =3D Regexp.new('(":)?(\\\\)?(' +
507 > WikiWords::WIKI_WORD_PATTERN + ')\b', 0, "utf-8")
508 >     end
510 All variables starting with a capital letter are constants (meaning
511 you can define them once, but never change them again).
513 >     def self.pattern
514 >       WIKI_WORD
515 >     end
517 Saying self. before a function name turns it into a class method,
518 instead of an instance method.  Which means you don't have to have an
519 instance of a WikiWord to call it.  Lesson 1 will also talk more about
520 class methods and instance methods.  (class methods are similar to
521 static methods in Java).
523 >     def initialize(match_data, content)
525 initialize is the magical method that gets called when you do new() on
526 an object.  So if you said:
528 Word.new(match_data, content)
530 it would call this method.
532 >       super
534 super calls the same method in the superclass (the class that we
535 inherit from), in this case it's WikiLink.
537 >       @textile_link_suffix, @escape, @page_name =3D match_data[1..3]
539 This sets the value of some instance methods to the second, third, and
540 fourth elements of the array match_data (we'll talk about arrays in
541 Lesson 2)
543 The below is a guess, since I'm not sure what all this stuff means
544 >       if @escape
545 >         @unmask_mode =3D :escape
546 >         @escaped_text =3D @page_name
547 >       else
548 >         @escaped_text =3D nil
549 >       end
551 if/else/end will be familar to anyone who's already done some
552 programming.  For those who haven't, they do exactly what they look
553 like: if @escape is true, do the two things after that, otherwise, do
554 the thing after else.
556 : before a variable turns it into a symbol.  It's actually a bit of a
557 tricky concept to understand, but most people just use them the same
558 way they would use constants (if I said :escape again elsewhere in the
559 program, it would have the same value and mean the same thing). It's
560 in the book, but we won't officially cover them.=20
561 http://www.rubycentral.com/faq/rubyfaq-6.html also talks about
562 symbols.
564 >       @link_text =3D WikiWords.separate(@page_name)
566 >       @unmask_text =3D (@escaped_text || @content.page_link(@page_name,
567 > @link_text, @link_type))
569 || is or.  We're assigning something to @unmask_text here.  If
570 @escaped_text is something, then @unmask_text will be @escaped_text.=20
571 Otherwise, @unmask_text will be the @content.page_link(...) thing.=20
572 (observant readers will notice that this seems like it's doing the
573 same thing as the if/else/end we talked about above.  ruby is like
574 perl in that there is more than one way to do many things).
576 @content.page_link(... is calling a method called page_link on the
577 @content object (we'll talk about objects and methods in Lesson 0)
579 >     end
580 >   end
582 The end.  Instead of using braces or spacing like other languages, in
583 Ruby we use the word end to tell it when we're done with certain
584 things (like if, class, or def in this example).
587 Laurel Fan
588 http://dreadnought.gorgorg.org
590 From katie@hoteldetective.org  Wed Nov  9 09:45:50 2005
591 Return-Path: <katie@hoteldetective.org>
592 X-Original-To: courses@linuxchix.org
593 Delivered-To: courses@linuxchix.org
594 Received: from localhost (localhost [127.0.0.1])
595         by www.linuxchix.org (Postfix) with ESMTP id BFFE427320B
596         for <courses@linuxchix.org>; Wed,  9 Nov 2005 09:45:50 +1100 (EST)
597 Received: from www.linuxchix.org ([127.0.0.1])
598         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
599         id 15519-07 for <courses@linuxchix.org>;
600         Wed, 9 Nov 2005 09:45:50 +1100 (EST)
601 X-Greylist: delayed 391 seconds by postgrey-1.21 at nest;
602         Wed, 09 Nov 2005 09:45:49 EST
603 Received: from mail27.sea5.speakeasy.net (mail27.sea5.speakeasy.net
604         [69.17.117.29])
605         by www.linuxchix.org (Postfix) with ESMTP id 6E9592731A8
606         for <courses@linuxchix.org>; Wed,  9 Nov 2005 09:45:48 +1100 (EST)
607 Received: (qmail 18201 invoked from network); 8 Nov 2005 22:39:07 -0000
608 Received: from dsl093-056-094.blt1.dsl.speakeasy.net (HELO katie-and-rob.org)
609         ([66.93.56.94]) (envelope-sender <katie@hoteldetective.org>)
610         by mail27.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP
611         for <courses@linuxchix.org>; 8 Nov 2005 22:39:07 -0000
612 Received: by katie-and-rob.org (nbSMTP-1.00) for uid 1000
613         katie@hoteldetective.org; Tue,  8 Nov 2005 17:37:59 -0500 (EST)
614 Date: Tue, 8 Nov 2005 17:37:57 -0500
615 From: Katie Bechtold <katie@hoteldetective.org>
616 To: courses@linuxchix.org
617 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
618         and your first homework assignment
619 Message-ID: <20051108223757.GN23556@blue.katie-and-rob.org>
620 Mail-Followup-To: courses@linuxchix.org
621 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
622 Mime-Version: 1.0
623 Content-Type: text/plain; charset=us-ascii
624 Content-Disposition: inline
625 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
626 X-Operating-System: Linux 2.4.20-gentoo-r9
627 X-PGP-Key: http://hoteldetective.org/katie/pgp_public_key 
628 User-Agent: Mutt/1.5.11
629 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
630 X-Topics: Introduction to Ruby
631 X-BeenThere: courses@linuxchix.org
632 X-Mailman-Version: 2.1.5
633 Precedence: list
634 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
635 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
636         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
637 List-Archive: <http://linuxchix.org/pipermail/courses>
638 List-Post: <mailto:courses@linuxchix.org>
639 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
640 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
641         <mailto:courses-request@linuxchix.org?subject=subscribe>
642 X-List-Received-Date: Tue, 08 Nov 2005 22:45:51 -0000
643 Content-Length: 2774
644 Lines: 76
646 > First, introduce yourself.  Do you know any other programming
647 > languages?  What do you like/not like about them?  Why are you
648 > interested in Ruby?  What are some things you'd like to learn to do?
650 Hi, I'm Katie!  Depending on the definition of "know", I know C,
651 C++, Java, Perl, Python, Fortran 77, Lisp, and Forth.  My favorites
652 among those are Python and Forth, both of which are flexible and
653 elegant, and both of which feature an interactive mode where you can
654 script "on the fly".  For me, the biggest sin of a programming
655 language is difficult readability, which is why I avoid Fortran like
656 the plague and haven't been able to appreciate Lisp as much as other
657 people.
659 I became interested in Ruby after reading Why's (Poignant) Guide to
660 Ruby[1] and hearing people rave about Ruby on Rails.  It looks like
661 Ruby's creator put a lot of thought into making life easier for
662 programmers.  I don't have any particular goals with respect to
663 Ruby; I'm just curious about it.
665 > Finally, look at the code.  Find a section of about 5-20 lines of
666 > code, and try to figure out what it does.
668 I found a Ruby application called rubyPod[2].  It's "a graphical
669 frontend for managing a iPod on Linux."  Here's a snippet from its
670 song.db:
672 class Song
673   include Comparable
675   ...
677   def <=>(songb)
678     if @pathSong==songb.pathSong
679       0
680     else
681       #if the path is not the same then the songs cannot be equal
682       if @nameArtist.downcase<songb.nameArtist.downcase
683         -1
684       elsif @nameArtist.downcase>songb.nameArtist.downcase
685         1
686       else
687         if @nameAlbum.downcase<songb.nameAlbum.downcase
688           -1
689         elsif @nameAlbum.downcase>songb.nameAlbum.downcase
690           1
691         else
692           @numSong.to_i<=>songb.numSong.to_i
693         end
694       end
695     end
696   end
699 What we have here is a method inside the Song class.  This method is
700 overloading Ruby's general comparison operator '<=>', which returns
701 -1, 0, or 1 depending on whether its left-hand operand is less then,
702 equal to, or greater than its right-hand operand.  Here, I think the
703 current Song object serves as the left-hand operand, and another
704 Song object denoted by 'songb' serves as the right-hand operand.
706 The first comparison in this function definition tests whether a
707 song is being compared to itself, to which it should be considered
708 equal.  The next test compares the lowercase version of the artist's
709 name (for case-insensitive sorting).  If those are equal, this
710 method compares the lowercase version of the album name.  If those
711 are also equal, it casts the songs' track numbers to integers and
712 compares them using the <=> operator for integers.
715 [1] http://poignantguide.net/ruby/
716 [2] http://rubypod.sourceforge.net/
718 -- 
719 Katie Bechtold         http://hoteldetective.org/
723 From laurel.fan@gmail.com  Mon Nov 14 11:38:58 2005
724 Return-Path: <laurel.fan@gmail.com>
725 X-Original-To: courses@linuxchix.org
726 Delivered-To: courses@linuxchix.org
727 Received: from localhost (localhost [127.0.0.1])
728         by www.linuxchix.org (Postfix) with ESMTP id 022CC27320D
729         for <courses@linuxchix.org>; Mon, 14 Nov 2005 11:38:57 +1100 (EST)
730 Received: from www.linuxchix.org ([127.0.0.1])
731         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
732         id 01419-06 for <courses@linuxchix.org>;
733         Mon, 14 Nov 2005 11:38:57 +1100 (EST)
734 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.196])
735         by www.linuxchix.org (Postfix) with ESMTP id 3D9892731AF
736         for <courses@linuxchix.org>; Mon, 14 Nov 2005 11:38:56 +1100 (EST)
737 Received: by xproxy.gmail.com with SMTP id s9so514927wxc
738         for <courses@linuxchix.org>; Sun, 13 Nov 2005 16:38:50 -0800 (PST)
739 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
740         h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
741         b=XX9TC+VuJTuxvMHo7cKTqIHP4HNGqxeK1Oao02bqj9R4LuI02lCalgmrK2VKoq5nu59Qc9fo+QhObyBeF5otq00uJKVdJOzLhdRVKhPi5MQuiK9Et++9eQC3eKkSxv28cK3C731V3rqc2wnjZ3j+h2UvB2Yka/FcZb9Se6N/riI=
742 Received: by 10.70.115.4 with SMTP id n4mr2713784wxc;
743         Fri, 11 Nov 2005 15:50:35 -0800 (PST)
744 Received: by 10.70.94.2 with HTTP; Fri, 11 Nov 2005 15:50:35 -0800 (PST)
745 Message-ID: <8b1e030f0511111550g71434216h962e2cf96194214b@mail.gmail.com>
746 Date: Fri, 11 Nov 2005 15:50:35 -0800
747 From: Laurel Fan <laurel.fan@gmail.com>
748 To: courses@linuxchix.org
749 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
750         and your first homework assignment
751 In-Reply-To: <20051108223757.GN23556@blue.katie-and-rob.org>
752 MIME-Version: 1.0
753 Content-Type: text/plain; charset=ISO-8859-1
754 Content-Transfer-Encoding: quoted-printable
755 Content-Disposition: inline
756 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
757         <20051108223757.GN23556@blue.katie-and-rob.org>
758 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
759 X-Topics: Introduction to Ruby
760 X-BeenThere: courses@linuxchix.org
761 X-Mailman-Version: 2.1.5
762 Precedence: list
763 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
764 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
765         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
766 List-Archive: <http://linuxchix.org/pipermail/courses>
767 List-Post: <mailto:courses@linuxchix.org>
768 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
769 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
770         <mailto:courses-request@linuxchix.org?subject=subscribe>
771 X-List-Received-Date: Mon, 14 Nov 2005 00:38:58 -0000
772 Content-Length: 2928
773 Lines: 80
775 On 11/8/05, Katie Bechtold <katie@hoteldetective.org> wrote:
776 > Hi, I'm Katie!
778 > My favorites
779 > among those are Python and Forth, both of which are flexible and
780 > elegant, and both of which feature an interactive mode where you can
781 > script "on the fly".
783 You should definitely check out irb then, if you haven't already.
785 > I found a Ruby application called rubyPod[2].  It's "a graphical
786 > frontend for managing a iPod on Linux."  Here's a snippet from its
787 > song.db:
789 > class Song
790 >   include Comparable
792 >   ...
794 >   def <=3D>(songb)
795 >     if @pathSong=3D=3Dsongb.pathSong
796 >       0
797 >     else
798 >       #if the path is not the same then the songs cannot be equal
799 >       if @nameArtist.downcase<songb.nameArtist.downcase
800 >         -1
801 >       elsif @nameArtist.downcase>songb.nameArtist.downcase
802 >         1
803 >       else
804 >         if @nameAlbum.downcase<songb.nameAlbum.downcase
805 >           -1
806 >         elsif @nameAlbum.downcase>songb.nameAlbum.downcase
807 >           1
808 >         else
809 >           @numSong.to_i<=3D>songb.numSong.to_i
810 >         end
811 >       end
812 >     end
813 >   end
814 > end
816 > What we have here is a method inside the Song class.  This method is
817 > overloading Ruby's general comparison operator '<=3D>', which returns
818 > -1, 0, or 1 depending on whether its left-hand operand is less then,
819 > equal to, or greater than its right-hand operand.  Here, I think the
820 > current Song object serves as the left-hand operand, and another
821 > Song object denoted by 'songb' serves as the right-hand operand.
823 > The first comparison in this function definition tests whether a
824 > song is being compared to itself, to which it should be considered
825 > equal.  The next test compares the lowercase version of the artist's
826 > name (for case-insensitive sorting).  If those are equal, this
827 > method compares the lowercase version of the album name.  If those
828 > are also equal, it casts the songs' track numbers to integers and
829 > compares them using the <=3D> operator for integers.
831 Great explanation!
833 A few other interesting things about this code:  Comparable is a mixin
834 (for those experienced with other OO languages, mixins are kind of
835 like multiple inheritance but actually not at all like it).  Including
836 Comparable lets you get a whole bunch of comparison operators
837 (between?, =3D=3D, <, >=3D, etc.), simply by implementing the <=3D> functio=
838 n.=20
839 Here's some documentation on Comparable:
841 http://ruby-doc.org/core/classes/Comparable.html
843 Enumerable is another very useful mixin.  We'll learn more about those
844 in Lesson 3, in the Modules chapter of the book.
846 Another thing you may notice is that there are no 'return' statements
847 anywhere.  Like perl and matlab (and probably other languages), if
848 there is no explicit return statement, the return value of the method
849 is the last statement evaluated.  We'll learn about methods in Lesson
850 1 (and then more about them in Lesson 2).
853 Laurel Fan
854 http://dreadnought.gorgorg.org
856 From chantal@antenna.nl  Wed Nov  9 21:27:34 2005
857 Return-Path: <chantal@antenna.nl>
858 X-Original-To: courses@linuxchix.org
859 Delivered-To: courses@linuxchix.org
860 Received: from localhost (localhost [127.0.0.1])
861         by www.linuxchix.org (Postfix) with ESMTP id 7A8AE27320B
862         for <courses@linuxchix.org>; Wed,  9 Nov 2005 21:27:34 +1100 (EST)
863 Received: from www.linuxchix.org ([127.0.0.1])
864         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
865         id 19551-10 for <courses@linuxchix.org>;
866         Wed, 9 Nov 2005 21:27:34 +1100 (EST)
867 Received: from site4u.nl (fanth.site4u.nl [194.9.84.88])
868         by www.linuxchix.org (Postfix) with ESMTP id 1199D2731AF
869         for <courses@linuxchix.org>; Wed,  9 Nov 2005 21:27:32 +1100 (EST)
870 Received: from [192.168.4.211] [62.221.235.161] by site4u.nl with ESMTP
871         (SMTPD32-8.15) id ACB15160078; Wed, 09 Nov 2005 11:17:21 +0100
872 Message-ID: <4371CF17.6040503@antenna.nl>
873 Date: Wed, 09 Nov 2005 11:27:35 +0100
874 From: Chantal Rosmuller <chantal@antenna.nl>
875 User-Agent: Mozilla Thunderbird 0.9 (X11/20041103)
876 X-Accept-Language: en-us, en
877 MIME-Version: 1.0
878 To: Laurel Fan <laurel.fan@gmail.com>
879 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References, and your first
880         homework assignment
881 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
882 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
883 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
884 Content-Transfer-Encoding: 7bit
885 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
886 X-Topics: Introduction to Ruby
887 Cc: courses@linuxchix.org
888 X-BeenThere: courses@linuxchix.org
889 X-Mailman-Version: 2.1.5
890 Precedence: list
891 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
892 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
893         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
894 List-Archive: <http://linuxchix.org/pipermail/courses>
895 List-Post: <mailto:courses@linuxchix.org>
896 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
897 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
898         <mailto:courses-request@linuxchix.org?subject=subscribe>
899 X-List-Received-Date: Wed, 09 Nov 2005 10:27:34 -0000
900 Content-Length: 1790
901 Lines: 54
903 Hi I'm Chantal, I am a linux/freebsd/windows sysadmin at a small 
904 internet service provider. I am definitely not an experienced programmer 
905 but I like to write some bash scripts every now and then to make my life 
906 as a sysadmin easier and more fun, and I know some php. I'm interested 
907 in ruby because I want to learn a new programming language and a lot of 
908 people seem to be enthusiastic about it, I guess I am just curious. I 
909 want to learn a language in which I can write more sophisticated 
910 sysadmin tools in the future and I thought ruby might be a candidate (or 
911 perl but I can learn that some other time too). Well anyway, here's my 
912 homework, some code I wrote myself, I needed to configure an interface 
913 on an openbsd system for a whole ip range and it had to put something 
914 like this:
916 inet alias x.y.z.1 255.255.255.0
917 inet alias x.y.z.2 255.255.255.0
921 I didn't want to type all of that so I wrote ipspitter.rb:
922 It basically takes a number to start with and adds one a number of times 
923 and keeps printing that, together with a string for the first three 
924 parts of the ip address and some text if you want
926 #!/usr/bin/ruby
928 puts "This is ipspitter"
929 puts "Which number do you want to start the range with?"
931 count = gets.to_i
932 sum = count
934 puts " How many ip addresses do you want?"
936 number = gets.to_i
937 number = number - 1
938 puts "Enter the first three parts of the ip-address (for example 
939 192.168.4. )"
940 range = gets.chomp
942 puts "Do you want to put some text in front of the ip-address? Put it here"
943 textbefore = gets.chomp
945 puts "Do you want to put some text after the ip-address? Put it here"
946 textafter = gets
948 puts textbefore + range + count.to_s + textafter
950 number.times do
951        count +=1
952        sum += count
953        puts textbefore + range + count.to_s + textafter
958 From rachel@xtreme.com  Wed Nov  9 22:14:17 2005
959 Return-Path: <rachel@xtreme.com>
960 X-Original-To: courses@linuxchix.org
961 Delivered-To: courses@linuxchix.org
962 Received: from localhost (localhost [127.0.0.1])
963         by www.linuxchix.org (Postfix) with ESMTP id D3AF827320B
964         for <courses@linuxchix.org>; Wed,  9 Nov 2005 22:14:16 +1100 (EST)
965 Received: from www.linuxchix.org ([127.0.0.1])
966         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
967         id 19914-10 for <courses@linuxchix.org>;
968         Wed, 9 Nov 2005 22:14:16 +1100 (EST)
969 X-Greylist: delayed 1221 seconds by postgrey-1.21 at nest;
970         Wed, 09 Nov 2005 22:14:16 EST
971 Received: from out4.smtp.messagingengine.com (out4.smtp.messagingengine.com
972         [66.111.4.28])
973         by www.linuxchix.org (Postfix) with ESMTP id 0D7B3273209
974         for <courses@linuxchix.org>; Wed,  9 Nov 2005 22:14:16 +1100 (EST)
975 Received: from frontend1.internal (mysql-sessions.internal [10.202.2.149])
976         by frontend1.messagingengine.com (Postfix) with ESMTP id ED468CDD396
977         for <courses@linuxchix.org>; Wed,  9 Nov 2005 05:53:44 -0500 (EST)
978 Received: from frontend2.messagingengine.com ([10.202.2.151])
979         by frontend1.internal (MEProxy); Wed, 09 Nov 2005 05:53:44 -0500
980 X-Sasl-enc: nfb8/YR2Ml6yAri6YJW2hVTpKCYDCji/hQFQ4HsRhCal 1131533624
981 Received: from [192.168.1.103] (c-67-188-109-17.hsd1.ca.comcast.net
982         [67.188.109.17])
983         by frontend2.messagingengine.com (Postfix) with ESMTP id 426885703A9
984         for <courses@linuxchix.org>; Wed,  9 Nov 2005 05:53:36 -0500 (EST)
985 Message-ID: <4371D52F.4030504@xtreme.com>
986 Date: Wed, 09 Nov 2005 02:53:35 -0800
987 From: Rachel McConnell <rachel@xtreme.com>
988 User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
989 X-Accept-Language: en-us, en
990 MIME-Version: 1.0
991 To: courses@linuxchix.org
992 Subject: Re: [Courses] [Ruby] Lesson 0 homework
993 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
994 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
995 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
996 Content-Transfer-Encoding: 7bit
997 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
998 X-Topics: Introduction to Ruby
999 X-BeenThere: courses@linuxchix.org
1000 X-Mailman-Version: 2.1.5
1001 Precedence: list
1002 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
1003 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1004         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
1005 List-Archive: <http://linuxchix.org/pipermail/courses>
1006 List-Post: <mailto:courses@linuxchix.org>
1007 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
1008 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1009         <mailto:courses-request@linuxchix.org?subject=subscribe>
1010 X-List-Received-Date: Wed, 09 Nov 2005 11:14:17 -0000
1011 Content-Length: 4455
1012 Lines: 131
1014 > First, introduce yourself.  Do you know any other programming
1015 > languages?  What do you like/not like about them?  Why are you
1016 > interested in Ruby?  What are some things you'd like to learn to do?
1018 Hello All, and thanks Laurel for organizing this!
1020 I've been programming in Java for about 5 years now, mostly webapps, 
1021 meaning that I use html and javascript extensively as well.  I used to 
1022 focus specifically on telephone apps, writing the UI in VoiceXML; but 
1023 testing your app by calling it up on the phone sucks really hard!  I can 
1024 get around in C# & ASP, and PHP, and get into trouble in Perl.  I have 
1025 to say I like them all except PHP, which makes it far too easy to write 
1026 bad code, and far too hard to write good code.  Good for beginners, though.
1029 > Second, find and run any ruby program.  It can be something you wrote,
1030 > something you downloaded (hint, look on RubyForge), an example you
1031 > copied out of a book, something a friend wrote for you, etc.
1033 > Finally, look at the code.  Find a section of about 5-20 lines of
1034 > code, and try to figure out what it does.  If you figure it out (or
1035 > just have a good guess), explain it to us.  If not, show us the code
1036 > and we'll try to explain it.
1038 I've got a very simple example, "cat" implemented in Ruby.  I more or 
1039 less wrote it - I found parts from here & there and put them together. 
1040 But I do understand what each line does, more or less, and it will run 
1041 if you put it in a file by itself.  But remove the line numbers first, 
1042 which I've added for reference!  Here goes:
1044 ----
1045   1  #! /usr/bin/ruby
1046   2
1047   3  fileName = ARGV[0] ? ARGV[0] : exit
1048   4
1049   5  begin
1050   6      IO.foreach(fileName) { | line |
1051   7          puts line
1052   8      }
1053   9  rescue
1054 10      $stderr.puts $!
1055 11  end
1056 ----
1058 LINE 1: the shebang line (i assume it's still called that in Ruby!) 
1059 Lets you run it without typing "ruby" first:
1061 $ ./cat.rb filename.txt
1063 of course, you can still run it through ruby:
1065 $ ruby cat.rb filename.txt
1068 LINE 3: Get the name of the file from the arguments list and assign it 
1069 to the variable, fileName.  (This is a SIMPLE cat function that only 
1070 looks at the first argument and ignores any others.)  If no argument is 
1071 provided, just stop right there.  I used the ternary operator, see 
1072 footnote [0] if you aren't familiar with it.
1075 LINE 5: Starts a block of code.  I'm almost certain that begin/end (see 
1076 line 11) are there as bookends to the rescue statement (line 9) to 
1077 explicitly delimit a block of code that is likely to throw an exception. 
1078   If the rescue wasn't needed, the begin/end wouldn't be either.
1081 LINE 6: This is the heart of cat.  IO is (I believe) a builtin Ruby 
1082 object that handles file input & output.  Its foreach method takes a 
1083 file name as argument, opens the file, and iterates through the lines in 
1084 the file.
1086 The bit with the pipe symbols after the open bracket is a mixin, and 
1087 it's the thing I'm least familiar with here....  I think it defines the 
1088 variable name for the object returned by the foreach method, for use 
1089 within the scope of the code block that comes after it.  I think it is a 
1090 little like the for each syntax, in Java 5:
1092 List<Line> linesInFile = getLines();
1093 for( Line line : linesInFile ) {
1094     // do stuff
1097 but, obviously, shorter.  I do know that "line" isn't a Ruby reserved 
1098 word here or anything, I tried "blarg" also and that worked just fine.
1100 Anyone can talk more about this, please do!
1103 LINE 7: puts is Ruby's print function.
1106 LINE 8: ends the scope of the variable, line (or blarg)
1109 LINE 9: rescue appears to be a Ruby catch statement.  IO stuff is always 
1110 dangerous and error-prone and most languages offer some way of 
1111 recovering from IO errors (no file, weird characters, permissions 
1112 problems, and so forth).
1115 LINE 10: what to do if there IS an error - print it out to standard 
1116 error (which may or may not be the same place a plain puts writes to).
1119 LINE 11: remember the begin statement in line 5?  we're done with that 
1120 block now.
1123 That's all, then.  I have to say that an in-depth analysis like that 
1124 helped ME a ton even for such a short little scrap of code.  NEXT!
1126 Rachel
1130 [0] The ternary operator is like a shortened IF/ELSE statement.  It 
1131 looks like this:
1133 TEST ? TRUE_RESULT : FALSE_RESULT
1135 As an IF statement, it would look like this:
1137 if( TEST ) {
1138    TRUE_RESULT;
1139 } else {
1140    FALSE_RESULT;
1143 It's called "ternary" because it has three arguments; it's the only 
1144 operator that takes more than two.
1146 From suzo@spin.net.au  Wed Nov  9 22:02:35 2005
1147 Return-Path: <suzo@spin.net.au>
1148 X-Original-To: courses@linuxchix.org
1149 Delivered-To: courses@linuxchix.org
1150 Received: from localhost (localhost [127.0.0.1])
1151         by www.linuxchix.org (Postfix) with ESMTP id B35A227320B
1152         for <courses@linuxchix.org>; Wed,  9 Nov 2005 22:02:35 +1100 (EST)
1153 Received: from www.linuxchix.org ([127.0.0.1])
1154         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
1155         id 19914-02 for <courses@linuxchix.org>;
1156         Wed, 9 Nov 2005 22:02:35 +1100 (EST)
1157 Received: from proxy.syd.comcen.com.au (comcen.comcen.com.au [203.23.236.66])
1158         by www.linuxchix.org (Postfix) with ESMTP id 60612273209
1159         for <courses@linuxchix.org>; Wed,  9 Nov 2005 22:02:35 +1100 (EST)
1160 Received: from angel.comcen.com.au (angel.comcen.com.au [203.23.236.69])
1161         by proxy.syd.comcen.com.au (8.11.6/8.11.6) with ESMTP id jA9B2Ym66516
1162         for <courses@linuxchix.org>; Wed, 9 Nov 2005 22:02:34 +1100 (EST)
1163         (envelope-from suzo@spin.net.au)
1164 Received: from [127.0.0.1] (202-172-117-64.cpe.nsw-1.comcen.com.au
1165         [202.172.117.64])
1166         by angel.comcen.com.au (8.13.4/8.12.9) with ESMTP id jA9B2Rui025085
1167         for <courses@linuxchix.org>; Wed, 9 Nov 2005 22:02:29 +1100 (EST)
1168 Message-ID: <4371D73C.1060707@spin.net.au>
1169 Date: Wed, 09 Nov 2005 22:02:20 +1100
1170 From: Sue Stones <suzo@spin.net.au>
1171 User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
1172 X-Accept-Language: en-us, en
1173 MIME-Version: 1.0
1174 Cc: courses@linuxchix.org
1175 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References, and your first
1176         homework assignment
1177 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1178 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1179 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
1180 Content-Transfer-Encoding: 7bit
1181 X-Comcen-MailScanner-Information: Please contact the ISP for more information
1182 X-Comcen-MailScanner: Found to be clean
1183 X-Comcen-MailScanner-SpamCheck: not spam, SpamAssassin (score=-2.48,
1184         required 8, autolearn=not spam, BAYES_00 -2.60,
1185         MISSING_HEADERS 0.12)
1186 X-Comcen-MailScanner-From: suzo@spin.net.au
1187 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
1188 X-Topics: Introduction to Ruby
1189 X-BeenThere: courses@linuxchix.org
1190 X-Mailman-Version: 2.1.5
1191 Precedence: list
1192 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
1193 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1194         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
1195 List-Archive: <http://linuxchix.org/pipermail/courses>
1196 List-Post: <mailto:courses@linuxchix.org>
1197 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
1198 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1199         <mailto:courses-request@linuxchix.org?subject=subscribe>
1200 X-List-Received-Date: Wed, 09 Nov 2005 11:02:36 -0000
1201 Content-Length: 1451
1202 Lines: 39
1204 Laurel Fan wrote:
1206 > First, introduce yourself. Do you know any other programming
1208 >languages?  What do you like/not like about them?  Why are you
1209 >interested in Ruby?  What are some things you'd like to learn to do?
1210 >  
1213 G'day,
1215 I intend to do this course, but as I am preparing for an exam next week 
1216 I won't actually start until after then. Still I thought that I would 
1217 give a short introduction.
1219 I know a lot of other languages, and I suppose that you could say that 
1220 learning new languages is a a bit of a hobby of mine. (Other people 
1221 collect stamps).  My biggest problem is that I don't know any language 
1222 really well.  What I like is languages that have different ways of 
1223 thinking about them, e.g. Prolog is very different to C which is also 
1224 very different to Java despite the similarities.  What I don't like is 
1225 VB which seems to be a mismash of different languages, and constantly 
1226 changing to try and copy the latest popular language.
1228 Ruby seems to have a different way of thinking associated with it, being 
1229 for one thing a totally Object oriented language, so that is the first 
1230 thing that got my interest.  Also speed of development seems to be part 
1231 of Ruby, and the promise of using Ruby on rails to develop a web 
1232 application painlessly seems worth investigating.
1234 I do have some applications where I may use Ruby if it seems 
1235 appropriate, but I need to know more about it before I can make any 
1236 decision like that!
1244 From beth-lists@compu-diva.com  Thu Nov 10 04:28:29 2005
1245 Return-Path: <beth-lists@compu-diva.com>
1246 X-Original-To: courses@linuxchix.org
1247 Delivered-To: courses@linuxchix.org
1248 Received: from localhost (localhost [127.0.0.1])
1249         by www.linuxchix.org (Postfix) with ESMTP id C5CE427320C
1250         for <courses@linuxchix.org>; Thu, 10 Nov 2005 04:28:29 +1100 (EST)
1251 Received: from www.linuxchix.org ([127.0.0.1])
1252         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
1253         id 22197-08 for <courses@linuxchix.org>;
1254         Thu, 10 Nov 2005 04:28:29 +1100 (EST)
1255 X-Greylist: delayed 395 seconds by postgrey-1.21 at nest;
1256         Thu, 10 Nov 2005 04:28:28 EST
1257 Received: from smtp4.superb.net (smtp4.superb.net [66.36.226.14])
1258         by www.linuxchix.org (Postfix) with SMTP id B70E52731AF
1259         for <courses@linuxchix.org>; Thu, 10 Nov 2005 04:28:28 +1100 (EST)
1260 Received: (qmail 15189 invoked by uid 503); 9 Nov 2005 17:21:47 -0000
1261 Received: from unknown (HELO ?192.168.0.100?)
1262         (beth%compu-diva.com@24.10.124.227)
1263         by 66.36.226.14 with ESMTPA; 9 Nov 2005 17:21:47 -0000
1264 Message-ID: <43722FEC.6040804@compu-diva.com>
1265 Date: Wed, 09 Nov 2005 09:20:44 -0800
1266 From: Beth Camero <beth-lists@compu-diva.com>
1267 User-Agent: Thunderbird 1.5 (Windows/20051025)
1268 MIME-Version: 1.0
1269 To: courses@linuxchix.org
1270 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References, and your first
1271         homework assignment
1272 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1273 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1274 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
1275 Content-Transfer-Encoding: 7bit
1276 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
1277 X-Topics: Introduction to Ruby
1278 X-BeenThere: courses@linuxchix.org
1279 X-Mailman-Version: 2.1.5
1280 Precedence: list
1281 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
1282 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1283         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
1284 List-Archive: <http://linuxchix.org/pipermail/courses>
1285 List-Post: <mailto:courses@linuxchix.org>
1286 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
1287 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1288         <mailto:courses-request@linuxchix.org?subject=subscribe>
1289 X-List-Received-Date: Wed, 09 Nov 2005 17:28:30 -0000
1290 Content-Length: 5302
1291 Lines: 148
1293 Hi all -
1294 I'm not going to get to this for a week either, so I'll just introduce
1295 myself.  My name is Beth Camero, I'm a 49 y.o. semi-geeky woman,
1296 managing network/desktop/web support for a mid-size non-profit
1297 association in Sacramento, California.  I've worked there for 15 years,
1298 and basically created the job I have.  I was hired lo those 15 years ago
1299 as a non-typing secretary who had never touched a computer.  Somebody
1300 there showed me WordPerfect on a little old PC (one of 3 stand-alones,
1301 tennis-shoe network only) and I fell in love.  Learned lots, became the
1302 computer guru for the office, grew a network and turned us into a
1303 [fairly] high-tech place.
1305 I'm probably in the wrong place.  I've never done any real programming
1306 but I'm interested in it.  I have programmers who come in and work for
1307 me occasionally and we do web projects together.  I don't remember where
1308 I ran across Ruby but it sounded so interesting that I thought I'd see
1309 if I could do it.  Worth a shot! I don't know anyone who is using it,
1310 but quickly creating web apps - what a concept! There are SO many things
1311 I'd like to do at work but don't have the $$ for the programming ...
1312 I'm going to be working on a Windoze system, I hope that won't be a
1313 problem.  I have a couple of Linux servers at work, but I don't have any
1314 Linux desktops.
1315 My kid is going to take this course, too - he's  a newbie
1316 programmer/techie but smart as a whip.  I'm hoping he'll  be able to
1317 help me. :)
1318 Wish me luck!
1319 Beth
1322 Laurel Fan wrote:
1323 > = Lesson 0: Installing and Documentation References
1325 > == Installing
1327 > === Linux
1329 > Any modern Linux distribution has ruby package(s).  It might even
1330 > already be installed.  (To check, try 'ruby --version' in a shell). If
1331 > you don't have it, install it with the appropriate package management
1332 > system.  The exact procedure will vary for your distribution.  To
1333 > start with, for yum-based systems, try::
1335 > # yum install ruby
1337 > and for apt-get based systems:
1339 > # apt-get install ruby
1341 > If you need more help, ask on the list.
1343 > In both Fedora and Debian, irb (interactive ruby, which has a better
1344 > interactive UI than the plain old ruby command) and ri (documentation
1345 > tool) are separate packages (called irb and ri).  You'll probably want
1346 > to install those as well.
1348 > === Windows
1350 > There's an installer for Windows here:
1352 > http://rubyinstaller.rubyforge.org/wiki/wiki.pl
1354 > === Mac OS X
1356 > Tiger (10.4) comes with Ruby installed.  For earlier versions, try
1357 > this page:
1359 > http://homepage.mac.com/discord/Ruby/
1361 > (I found it on a google search and haven't tried it, so if you do, let
1362 > us know how it goes.)
1364 > == Documentation References
1366 > There are lots of places to find documentation for Ruby.  Sinc nearly
1367 > everything you'd search for is an actual word (including 'ruby'
1368 > itself, of course), it can be hard to google for.
1370 > If you have the 2nd edition of the book, the API reference that starts
1371 > in about the middle of the book is great.  With the 1st edition, some
1372 > of that will be out of date.
1374 > The canonical source for online documentation is:
1376 > http://ruby-doc.org/
1378 > If you have Firefox/Mozilla, there's a fancy sidebar for ruby-doc:
1380 > http://ruby-doc.org/docbar/
1382 > If you have the 'ri' commad, you can use that for
1383 > documentation for libraries that you have installed.  For example:
1385 >   
1386 >> ri File.new
1387 >>     
1388 > -------------------------------------------------------------- File::new
1389 >      File.new(filename, mode="r")            => file
1390 >      File.new(filename [, mode [, perm]])    => file
1391 > ------------------------------------------------------------------------
1392 >      Opens the file named by _filename_ according to _mode_ (default is
1394 > [...]
1396 > Finally, here is another online ruby book featuring cartoon foxes:
1398 > http://www.poignantguide.net/ruby/
1400 > Other websites that may be useful include:
1402 > RubyForge: http://rubyforge.org
1403 > Ruby home page (in English): http://ruby-lang.org/en
1406 > == Homework
1408 > Please 'turn in' your homework on the courses list, using the [Ruby]
1409 > subject tag, and with a subject that has something about 'lesson 0'
1410 > and 'homework'.  It's not due by a specific time, but I would
1411 > recommend starting before the next lesson is posted (Mon Nov 14).
1413 > First, introduce yourself.  Do you know any other programming
1414 > languages?  What do you like/not like about them?  Why are you
1415 > interested in Ruby?  What are some things you'd like to learn to do?
1417 > Second, find and run any ruby program.  It can be something you wrote,
1418 > something you downloaded (hint, look on RubyForge), an example you
1419 > copied out of a book, something a friend wrote for you, etc.
1421 > Finally, look at the code.  Find a section of about 5-20 lines of
1422 > code, and try to figure out what it does.  If you figure it out (or
1423 > just have a good guess), explain it to us.  If not, show us the code
1424 > and we'll try to explain it.
1426 > That's it, Lesson 1 (covering Chapters 1-3 of the book, "Getting
1427 > Started", "Ruby.new", and "Classes, Objects, and Variables") is next
1428 > week, Mon Nov 14.  See you on the list!
1430 > --
1431 > Laurel Fan
1432 > http://dreadnought.gorgorg.org
1433 > _______________________________________________
1434 > Courses mailing list
1435 > Courses@linuxchix.org
1436 > http://mailman.linuxchix.org/mailman/listinfo/courses
1438 >   
1442 From joseph.hall@gmail.com  Thu Nov 10 06:47:49 2005
1443 Return-Path: <joseph.hall@gmail.com>
1444 X-Original-To: courses@linuxchix.org
1445 Delivered-To: courses@linuxchix.org
1446 Received: from localhost (localhost [127.0.0.1])
1447         by www.linuxchix.org (Postfix) with ESMTP id 72A0927320C
1448         for <courses@linuxchix.org>; Thu, 10 Nov 2005 06:47:49 +1100 (EST)
1449 Received: from www.linuxchix.org ([127.0.0.1])
1450         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
1451         id 23070-02 for <courses@linuxchix.org>;
1452         Thu, 10 Nov 2005 06:47:49 +1100 (EST)
1453 X-Greylist: delayed 2549 seconds by postgrey-1.21 at nest;
1454         Thu, 10 Nov 2005 06:47:48 EST
1455 Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.202])
1456         by www.linuxchix.org (Postfix) with ESMTP id 87C9E2731A8
1457         for <courses@linuxchix.org>; Thu, 10 Nov 2005 06:47:48 +1100 (EST)
1458 Received: by wproxy.gmail.com with SMTP id 71so198621wri
1459         for <courses@linuxchix.org>; Wed, 09 Nov 2005 11:47:45 -0800 (PST)
1460 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
1461         h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
1462         b=P0oiMK4z4nQOOJux8miK5pIayRTJXqcXo5e6G8DRXkOS3280iA7yDjP6T+eymvdq8FSzAArDKU61EEB/iArHmLvw4Fyu1iUwVtRX8v9mto40zgMeHEDGMgaqmQ2BOBqIK9i8EfEVAMOzHTDKVCyuvPsMCPK4ST+p1wRsGu2KNO4=
1463 Received: by 10.65.197.18 with SMTP id z18mr1186103qbp;
1464         Wed, 09 Nov 2005 11:05:15 -0800 (PST)
1465 Received: by 10.64.199.7 with HTTP; Wed, 9 Nov 2005 11:05:15 -0800 (PST)
1466 Message-ID: <94fd50290511091105s38d341e1j5cb3be8a8a568258@mail.gmail.com>
1467 Date: Wed, 9 Nov 2005 11:05:15 -0800
1468 From: Joseph Hall <joseph.hall@gmail.com>
1469 To: courses@linuxchix.org
1470 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
1471         and your first homework assignment
1472 In-Reply-To: <43722FEC.6040804@compu-diva.com>
1473 MIME-Version: 1.0
1474 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1475         <43722FEC.6040804@compu-diva.com>
1476 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
1477 Content-Type: text/plain; charset=ISO-8859-1
1478 Content-Transfer-Encoding: quoted-printable
1479 Content-Disposition: inline
1480 X-Content-Filtered-By: Mailman/MimeDel 2.1.5
1481 X-Topics: Introduction to Ruby
1482 X-BeenThere: courses@linuxchix.org
1483 X-Mailman-Version: 2.1.5
1484 Precedence: list
1485 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
1486 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1487         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
1488 List-Archive: <http://linuxchix.org/pipermail/courses>
1489 List-Post: <mailto:courses@linuxchix.org>
1490 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
1491 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1492         <mailto:courses-request@linuxchix.org?subject=subscribe>
1493 X-List-Received-Date: Wed, 09 Nov 2005 19:47:49 -0000
1494 Content-Length: 1710
1495 Lines: 62
1497 Hello,
1499 My name is Joseph Hall. I've used C++ and Java the most "for real" (at
1500 work), but in college I TA'ed Programming Languages and we went over Java,
1501 Scheme, and Miranda. I also was forced to learn and use Perl at work but I
1502 don't like it. The last couple of weeks at work I've been using a language
1503 called LUA, which is lightweight, fast, stack-based, and the interpreter is
1504 easily embedded in C/C++ apps. Right now I know very little about Ruby. I
1505 want to learn Ruby for fun, not necessarily because I think I'll use it. I
1506 am also interested in participating because I am Laurel's b.f.
1508 I found some simple Ruby on the internet and tweaked it.
1511 #!/usr/bin/ruby
1513 def fib(n)
1514 a =3D 0
1515 b =3D 1
1516 n.times do
1517 a, b =3D b, a+b
1522 N =3D Integer(ARGV.shift || 1)
1523 print "Fib(", N, ") is ", fib(N), "\n"
1527 This is computing Fibonacci numbers. I guess the ARGV line is getting
1528 command line parameters, and defaulting to "1" if none are given. Pretty
1529 readable yet compact. Why does N need an explicit Integer()
1530 cast/type/whatever but a and b don't? In Perl I wouldn't need that...
1532 Since I know Scheme, I wanted to compare. I wrote this Scheme to do the sam=
1534 thing:
1537 (define (fib n)
1538 (fib-helper n 1 1))
1540 (define (fib-helper n a b)
1541 (if (<=3D n 1)
1543 (fib-helper (- n 1) b (+ a b))))
1545 (fib 150000)
1548 Even though this is a really simple algorithm, you need a helper function i=
1550 Scheme in order to really get it right. The "a, b =3D" syntax in Ruby is
1551 pretty cool.
1553 I would expect the runtime of each to be comparable, but for large N the
1554 Ruby is much faster than Scheme. I know nothing, but I'm venturing a guess
1555 that Ruby is somehow compiled, whereas the Scheme is completely
1556 interpreted...?
1560 From laurel.fan@gmail.com  Thu Nov 17 03:13:09 2005
1561 Return-Path: <laurel.fan@gmail.com>
1562 X-Original-To: courses@linuxchix.org
1563 Delivered-To: courses@linuxchix.org
1564 Received: from localhost (localhost [127.0.0.1])
1565         by www.linuxchix.org (Postfix) with ESMTP id 180D2273210
1566         for <courses@linuxchix.org>; Thu, 17 Nov 2005 03:13:09 +1100 (EST)
1567 Received: from www.linuxchix.org ([127.0.0.1])
1568         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
1569         id 23197-01 for <courses@linuxchix.org>;
1570         Thu, 17 Nov 2005 03:13:08 +1100 (EST)
1571 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.205])
1572         by www.linuxchix.org (Postfix) with ESMTP id 45B8E2731FC
1573         for <courses@linuxchix.org>; Thu, 17 Nov 2005 03:13:07 +1100 (EST)
1574 Received: by xproxy.gmail.com with SMTP id s9so1106276wxc
1575         for <courses@linuxchix.org>; Wed, 16 Nov 2005 08:13:05 -0800 (PST)
1576 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
1577         h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
1578         b=kbsxVjWecnBIXudSxT8+Mslgr07rC3u8xXbXtDoN83EL5i3za5yiV/YJ3qK0aKNPHieBHPdnyA95L5BRovZgSP/Rg6YwB9A6mj5Ivombl0XLpAfGjY4q6g9yh+8gaw9n0dA6pUREXLXHmwKhWOve7JkLgZQP74wyGL7zy0YuDTg=
1579 Received: by 10.70.69.8 with SMTP id r8mr4022223wxa;
1580         Wed, 16 Nov 2005 07:45:32 -0800 (PST)
1581 Received: by 10.70.94.2 with HTTP; Wed, 16 Nov 2005 07:45:32 -0800 (PST)
1582 Message-ID: <8b1e030f0511160745ue7d17ep81dcfcbe77a5a9f5@mail.gmail.com>
1583 Date: Wed, 16 Nov 2005 07:45:32 -0800
1584 From: Laurel Fan <laurel.fan@gmail.com>
1585 To: courses@linuxchix.org
1586 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
1587         and your first homework assignment
1588 In-Reply-To: <94fd50290511091105s38d341e1j5cb3be8a8a568258@mail.gmail.com>
1589 MIME-Version: 1.0
1590 Content-Type: text/plain; charset=ISO-8859-1
1591 Content-Transfer-Encoding: quoted-printable
1592 Content-Disposition: inline
1593 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1594         <43722FEC.6040804@compu-diva.com>
1595         <94fd50290511091105s38d341e1j5cb3be8a8a568258@mail.gmail.com>
1596 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
1597 X-Topics: Introduction to Ruby
1598 X-BeenThere: courses@linuxchix.org
1599 X-Mailman-Version: 2.1.5
1600 Precedence: list
1601 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
1602 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1603         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
1604 List-Archive: <http://linuxchix.org/pipermail/courses>
1605 List-Post: <mailto:courses@linuxchix.org>
1606 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
1607 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1608         <mailto:courses-request@linuxchix.org?subject=subscribe>
1609 X-List-Received-Date: Wed, 16 Nov 2005 16:13:09 -0000
1610 Content-Length: 1802
1611 Lines: 63
1613 On 11/9/05, Joseph Hall <joseph.hall@gmail.com> wrote:
1614 > Hello,
1618 > I found some simple Ruby on the internet and tweaked it.
1620 > ---
1621 > #!/usr/bin/ruby
1623 > def fib(n)
1624 > a =3D 0
1625 > b =3D 1
1626 > n.times do
1627 > a, b =3D b, a+b
1628 > end
1629 > a
1630 > end
1632 > N =3D Integer(ARGV.shift || 1)
1633 > print "Fib(", N, ") is ", fib(N), "\n"
1634 > ---
1637 > This is computing Fibonacci numbers. I guess the ARGV line is getting
1638 > command line parameters, and defaulting to "1" if none are given
1640 Yep.  ARGV is a list containing all of the command line parameters
1641 (not including the filename of the program itself, which will be
1642 different for C programmers.  That's in $0).
1644 > Why does N need an explicit Integer()
1645 > cast/type/whatever but a and b don't?
1646 > In Perl I wouldn't need that...
1648 This is because Ruby is strongly typed but Perl isn't.  Ruby is also
1649 dynamically typed (and it has "duck typing" which I haven't seen in
1650 any other mainstream language), which is why  you didn't have to say
1651 anything like:
1653 int a =3D 0
1655 You assigned it to a Fixnum, so a is a Fixnum.
1657 However, for N, the result of ARGV.shift is a String, so it needs to
1658 be turned into an integer.
1660 > I would expect the runtime of each to be comparable, but for large N the
1661 > Ruby is much faster than Scheme. I know nothing, but I'm venturing a gues=
1663 > that Ruby is somehow compiled, whereas the Scheme is completely
1664 > interpreted...?
1666 No, ruby is completely interpreted.  I think there are ways of
1667 compiling it, at least into bytecode, but those are fairly obscure.=20
1668 Maybe it's just because the scheme is recursive and the perl is not?=20
1669 I don't know Scheme that well (my obligatory college class functional
1670 language was ML), but does it look like the Scheme interpreter should
1671 be doing a tail call optimization?
1674 Laurel Fan
1675 http://dreadnought.gorgorg.org
1677 From qirien@icecavern.net  Sat Nov 12 05:00:08 2005
1678 Return-Path: <qirien@icecavern.net>
1679 X-Original-To: courses@linuxchix.org
1680 Delivered-To: courses@linuxchix.org
1681 Received: from localhost (localhost [127.0.0.1])
1682         by www.linuxchix.org (Postfix) with ESMTP id 61EF727320E
1683         for <courses@linuxchix.org>; Sat, 12 Nov 2005 05:00:08 +1100 (EST)
1684 Received: from www.linuxchix.org ([127.0.0.1])
1685         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
1686         id 07483-03 for <courses@linuxchix.org>;
1687         Sat, 12 Nov 2005 05:00:08 +1100 (EST)
1688 X-Greylist: delayed 308 seconds by postgrey-1.21 at nest;
1689         Sat, 12 Nov 2005 05:00:07 EST
1690 Received: from sccrmhc12.comcast.net (unknown [63.240.77.82])
1691         by www.linuxchix.org (Postfix) with ESMTP id A22D527320D
1692         for <courses@linuxchix.org>; Sat, 12 Nov 2005 05:00:07 +1100 (EST)
1693 Received: from mail.icecavern.net ([68.35.95.14])
1694         by comcast.net (sccrmhc12) with ESMTP
1695         id <200511111754290120027hi0e>; Fri, 11 Nov 2005 17:54:40 +0000
1696 Received: from cactuar.icecavern.net (cactuar.icecavern.net [10.0.0.8])
1697         by mail.icecavern.net (Postfix) with ESMTP id 95991136FF
1698         for <courses@linuxchix.org>; Fri, 11 Nov 2005 10:54:04 -0700 (MST)
1699 From: Andrea Landaker <qirien@icecavern.net>
1700 To: courses@linuxchix.org
1701 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
1702         and your first homework assignment
1703 Date: Fri, 11 Nov 2005 10:54:23 -0700
1704 User-Agent: KMail/1.8.2
1705 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1706         <43722FEC.6040804@compu-diva.com>
1707 In-Reply-To: <43722FEC.6040804@compu-diva.com>
1708 MIME-Version: 1.0
1709 Content-Type: text/plain;
1710   charset="iso-8859-1"
1711 Content-Transfer-Encoding: 7bit
1712 Content-Disposition: inline
1713 Message-Id: <200511111054.24525.qirien@icecavern.net>
1714 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
1715 X-Topics: Introduction to Ruby
1716 X-BeenThere: courses@linuxchix.org
1717 X-Mailman-Version: 2.1.5
1718 Precedence: list
1719 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
1720 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1721         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
1722 List-Archive: <http://linuxchix.org/pipermail/courses>
1723 List-Post: <mailto:courses@linuxchix.org>
1724 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
1725 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1726         <mailto:courses-request@linuxchix.org?subject=subscribe>
1727 X-List-Received-Date: Fri, 11 Nov 2005 18:00:08 -0000
1728 Content-Length: 1630
1729 Lines: 48
1731 I'm a computer programmer turned stay-at-home-mom, who still loves 
1732 computers.  :-)  Most of my programming these days is simple Ruby scripts for 
1733 myself or for my website (an audio/image gallery program, recoding mp3s, 
1734 etc).  In the past I've used Java, C++, and Scheme, but I'm a big fan of 
1735 Ruby.  I have never really sat down and "learned" it, though -- just started 
1736 ploughing through getting things to work.  So I'm looking forward to learning 
1737 some (probably basic) new things that I hadn't thought I needed but will 
1738 probably be useful.
1740 Not sure if I'll make it through the whole course due to the fact that my 
1741 1-year-old hates me being on the computer (he likes to turn it off), but 
1742 it'll be fun!
1744 OK, for the next part of the homework, here's my husband's interactive 
1745 crytpogram solver:
1747 #!/usr/bin/ruby
1749 $code = ARGV.join(' ').upcase
1751 puts $code
1752 print '$ '
1753 STDOUT.flush
1754 while STDIN.gets
1755   if ~ /([A-Za-z]{2}).*/
1756     code = $1[0..0].upcase
1757     text = $1[1..1].upcase
1758     $code.gsub!(code,'!')
1759     $code.gsub!(text,code)
1760     $code.gsub!('!',text)
1761   else
1762     puts "Enter xY to make x -> Y"
1763   end
1764   puts $code
1765   print '$ '
1766   STDOUT.flush
1769 The first line puts all the "arguments" (the cryptogram itself) into the 
1770 global variable "code", uppercased.  It prints it out, and then takes two 
1771 letters from the user.  The first letter goes in the local variable "code", 
1772 and the second goes into "text".  Then, throughout the global variable 
1773 "code", it swaps the two (using the exclamation point for an intermediary 
1774 character).  This repeats essentially forever.
1776 -- 
1777 Andrea Landaker
1778 http://www.icecavern.net/~qirien/
1780 From laurel.fan@gmail.com  Thu Nov 17 03:47:31 2005
1781 Return-Path: <laurel.fan@gmail.com>
1782 X-Original-To: courses@linuxchix.org
1783 Delivered-To: courses@linuxchix.org
1784 Received: from localhost (localhost [127.0.0.1])
1785         by www.linuxchix.org (Postfix) with ESMTP id 5C898273210
1786         for <courses@linuxchix.org>; Thu, 17 Nov 2005 03:47:31 +1100 (EST)
1787 Received: from www.linuxchix.org ([127.0.0.1])
1788         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
1789         id 23313-02 for <courses@linuxchix.org>;
1790         Thu, 17 Nov 2005 03:47:31 +1100 (EST)
1791 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.195])
1792         by www.linuxchix.org (Postfix) with ESMTP id A05FA2731AF
1793         for <courses@linuxchix.org>; Thu, 17 Nov 2005 03:47:30 +1100 (EST)
1794 Received: by xproxy.gmail.com with SMTP id s9so1114437wxc
1795         for <courses@linuxchix.org>; Wed, 16 Nov 2005 08:47:27 -0800 (PST)
1796 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
1797         h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
1798         b=S35B6qyvFXS9dKpJX7rs3VS2sNNH1nu/0szRJF/xZuoFe18AdUKSpkYFghw0cnMxoBCMCMXpiV2/M8m7B6Gdfysc5wgPcWWQFf5pSjgKbw63Lfn580Qm93nB+e6ffs78z/gjU1hp8BeKFIAG4eZ2TlKz/iqBDsZ7tydN2g9rFsY=
1799 Received: by 10.70.78.12 with SMTP id a12mr4056382wxb;
1800         Wed, 16 Nov 2005 08:23:00 -0800 (PST)
1801 Received: by 10.70.94.2 with HTTP; Wed, 16 Nov 2005 08:23:00 -0800 (PST)
1802 Message-ID: <8b1e030f0511160823k2403986ay8241c623ea27b9dd@mail.gmail.com>
1803 Date: Wed, 16 Nov 2005 08:23:00 -0800
1804 From: Laurel Fan <laurel.fan@gmail.com>
1805 To: courses@linuxchix.org
1806 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
1807         and your first homework assignment
1808 In-Reply-To: <200511111054.24525.qirien@icecavern.net>
1809 MIME-Version: 1.0
1810 Content-Type: text/plain; charset=ISO-8859-1
1811 Content-Transfer-Encoding: quoted-printable
1812 Content-Disposition: inline
1813 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1814         <43722FEC.6040804@compu-diva.com>
1815         <200511111054.24525.qirien@icecavern.net>
1816 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
1817 X-Topics: Introduction to Ruby
1818 X-BeenThere: courses@linuxchix.org
1819 X-Mailman-Version: 2.1.5
1820 Precedence: list
1821 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
1822 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1823         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
1824 List-Archive: <http://linuxchix.org/pipermail/courses>
1825 List-Post: <mailto:courses@linuxchix.org>
1826 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
1827 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1828         <mailto:courses-request@linuxchix.org?subject=subscribe>
1829 X-List-Received-Date: Wed, 16 Nov 2005 16:47:31 -0000
1830 Content-Length: 2298
1831 Lines: 67
1833 On 11/11/05, Andrea Landaker <qirien@icecavern.net> wrote:
1835 Hi Andrea!
1837 > OK, for the next part of the homework, here's my husband's interactive
1838 > crytpogram solver:
1840 Looks good!  Great example of using regular expressions and the gsub
1841 function, which Perl programmes may be interested in..
1843 > #!/usr/bin/ruby
1845 > $code =3D ARGV.join(' ').upcase
1847 > puts $code
1848 > print '$ '
1849 > STDOUT.flush
1850 > while STDIN.gets
1851 >   if ~ /([A-Za-z]{2}).*/
1852 >     code =3D $1[0..0].upcase
1853 >     text =3D $1[1..1].upcase
1855 This [0..0] stuff is necessary because $1[0] would return a character
1856 (which is actually a number, not a String).  Telling it [0..0] gives
1857 it a range (here, it's the range from 0 to 0, the first character to
1858 the first character), which makes it return a String.
1860 >     $code.gsub!(code,'!')
1862 gsub is "global substitution" (see String documentation for more).=20
1863 What the exclamation mark does is do the gsub on $code itself (rather
1864 than returning the result of doing gsub).  It's the same thing as:
1866 $code =3D $code.gsub(code, '!')
1868 One style note:  I would avoid using very similar variable names like
1869 $code/code.  On the first read through I wasn't mentally pronouncing
1870 the $, so I was very confused about what was going on.  The $ actually
1871 means global variable, which in this case doesn't do much because you
1872 have only one function anyway.  It's usually preferable to avoid
1873 global variables for longer or more complicated programs.  However,
1874 one benefit of Ruby is that if you're doing something simple enough
1875 (like this) that OO and encapsulation won't help you, it won't get in
1876 your way.  But using $ makes it look like Perl and we don't want that
1879 >     $code.gsub!(text,code)
1880 >     $code.gsub!('!',text)
1881 >   else
1882 >     puts "Enter xY to make x -> Y"
1883 >   end
1884 >   puts $code
1885 >   print '$ '
1886 >   STDOUT.flush
1887 > end
1889 > The first line puts all the "arguments" (the cryptogram itself) into the
1890 > global variable "code", uppercased.  It prints it out, and then takes two
1891 > letters from the user.  The first letter goes in the local variable "code=
1893 > and the second goes into "text".  Then, throughout the global variable
1894 > "code", it swaps the two (using the exclamation point for an intermediary
1895 > character).  This repeats essentially forever.
1898 Laurel Fan
1899 http://dreadnought.gorgorg.org
1901 From laurel.fan@gmail.com  Thu Nov 17 09:46:17 2005
1902 Return-Path: <laurel.fan@gmail.com>
1903 X-Original-To: courses@linuxchix.org
1904 Delivered-To: courses@linuxchix.org
1905 Received: from localhost (localhost [127.0.0.1])
1906         by www.linuxchix.org (Postfix) with ESMTP id 87105273211
1907         for <courses@linuxchix.org>; Thu, 17 Nov 2005 09:46:17 +1100 (EST)
1908 Received: from www.linuxchix.org ([127.0.0.1])
1909         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
1910         id 25533-02 for <courses@linuxchix.org>;
1911         Thu, 17 Nov 2005 09:46:17 +1100 (EST)
1912 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.205])
1913         by www.linuxchix.org (Postfix) with ESMTP id C6B09273208
1914         for <courses@linuxchix.org>; Thu, 17 Nov 2005 09:46:16 +1100 (EST)
1915 Received: by xproxy.gmail.com with SMTP id s9so1183813wxc
1916         for <courses@linuxchix.org>; Wed, 16 Nov 2005 14:46:14 -0800 (PST)
1917 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
1918         h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
1919         b=dVIJLN7gZ2+IY3geV1UK9rbDi5GmfMyJto+yA4AxnTNfncRLDVIJOVFYqXIzIGB0XHB73bR9Ss9bGRraj+EMtYD/C2yYIVl98uSzJFEAB1UaBbxja009s2jpP/rv8nw1a3dmqxJyrCUOelKcRE+JSpHE0vL3Y/muUBsVvH7BhIE=
1920 Received: by 10.70.77.6 with SMTP id z6mr4008504wxa;
1921         Wed, 16 Nov 2005 07:23:21 -0800 (PST)
1922 Received: by 10.70.94.2 with HTTP; Wed, 16 Nov 2005 07:23:12 -0800 (PST)
1923 Message-ID: <8b1e030f0511160723v34ce6193jc3e50cd67c4afc83@mail.gmail.com>
1924 Date: Wed, 16 Nov 2005 07:23:21 -0800
1925 From: Laurel Fan <laurel.fan@gmail.com>
1926 To: courses@linuxchix.org
1927 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
1928         and your first homework assignment
1929 In-Reply-To: <43722FEC.6040804@compu-diva.com>
1930 MIME-Version: 1.0
1931 Content-Type: text/plain; charset=ISO-8859-1
1932 Content-Transfer-Encoding: quoted-printable
1933 Content-Disposition: inline
1934 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1935         <43722FEC.6040804@compu-diva.com>
1936 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
1937 X-Topics: Introduction to Ruby
1938 X-BeenThere: courses@linuxchix.org
1939 X-Mailman-Version: 2.1.5
1940 Precedence: list
1941 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
1942 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1943         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
1944 List-Archive: <http://linuxchix.org/pipermail/courses>
1945 List-Post: <mailto:courses@linuxchix.org>
1946 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
1947 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
1948         <mailto:courses-request@linuxchix.org?subject=subscribe>
1949 X-List-Received-Date: Wed, 16 Nov 2005 22:46:17 -0000
1950 Content-Length: 347
1951 Lines: 14
1953 On 11/9/05, Beth Camero <beth-lists@compu-diva.com> wrote:
1954 > Hi all -
1958 > I'm probably in the wrong place.  I've never done any real programming
1959 > but I'm interested in it.
1961 Well, this sounds like a great place for you to me, personally, but
1962 I'm biased.  I hope you and your son enjoy the course!
1965 Laurel Fan
1966 http://dreadnought.gorgorg.org
1968 From akkana@shallowsky.com  Thu Nov 10 07:12:27 2005
1969 Return-Path: <akkana@shallowsky.com>
1970 X-Original-To: courses@linuxchix.org
1971 Delivered-To: courses@linuxchix.org
1972 Received: from localhost (localhost [127.0.0.1])
1973         by www.linuxchix.org (Postfix) with ESMTP id C50AF27320C
1974         for <courses@linuxchix.org>; Thu, 10 Nov 2005 07:12:27 +1100 (EST)
1975 Received: from www.linuxchix.org ([127.0.0.1])
1976         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
1977         id 23215-08 for <courses@linuxchix.org>;
1978         Thu, 10 Nov 2005 07:12:27 +1100 (EST)
1979 Received: from moon.timocharis.com (adsl-69-105-235-1.dsl.pltn13.pacbell.net
1980         [69.105.235.1])
1981         by www.linuxchix.org (Postfix) with ESMTP id ED5C12731FC
1982         for <courses@linuxchix.org>; Thu, 10 Nov 2005 07:12:26 +1100 (EST)
1983 Received: by moon.timocharis.com (Postfix, from userid 666)
1984         id 4A9C78AC4; Wed,  9 Nov 2005 12:12:21 -0800 (PST)
1985 Date: Wed, 9 Nov 2005 12:12:21 -0800
1986 From: Akkana Peck <akkana@shallowsky.com>
1987 To: courses@linuxchix.org
1988 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
1989         and your first homework assignment
1990 Message-ID: <20051109201221.GA9900@shallowsky.com>
1991 Mail-Followup-To: courses@linuxchix.org
1992 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1993 Mime-Version: 1.0
1994 Content-Type: text/plain; charset=us-ascii
1995 Content-Disposition: inline
1996 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
1997 User-Agent: Mutt/1.5.9i
1998 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
1999 X-Topics: Introduction to Ruby
2000 X-BeenThere: courses@linuxchix.org
2001 X-Mailman-Version: 2.1.5
2002 Precedence: list
2003 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
2004 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2005         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
2006 List-Archive: <http://linuxchix.org/pipermail/courses>
2007 List-Post: <mailto:courses@linuxchix.org>
2008 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
2009 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2010         <mailto:courses-request@linuxchix.org?subject=subscribe>
2011 X-List-Received-Date: Wed, 09 Nov 2005 20:12:28 -0000
2012 Content-Length: 4564
2013 Lines: 102
2015 Hi! Laurel, thanks for running the course.
2017 I'm a longtime programmer in lots of languages. My two favorites
2018 are C and Python; I suppose because they're simple, compact and
2019 efficient. I've used Ruby and Rails a little bit, but I want to
2020 learn more about Ruby because although I can get by in it, I
2021 don't feel like I understand it as well as I'd like to.
2023 I expect most of my Ruby use will be for Rails, but who knows?
2024 Maybe the course will convince me that I should use it instead of
2025 Python for writing standalone scripts. And every language has
2026 strengths and weaknesses, so even if I don't switch to Ruby as
2027 my main scripting language, I'm sure there will be times when it's
2028 the best tool for the job.
2030 Laurel Fan writes:
2031 > Any modern Linux distribution has ruby package(s).  It might even
2032 > already be installed.  (To check, try 'ruby --version' in a shell). If
2034 I'm currently running Ubuntu "Hoary Hedgehog". Although it offers
2035 Ruby packages (which are probably fine for this course), I didn't
2036 have much luck getting Rails and Gems to work, even after adding the
2037 backports from Breezy. Also, the built-in Ruby didn't install a
2038 "ruby" command so I had to make a symlink (I notice someone else
2039 just asked about that on newchix recently).
2041 I ended up building Ruby and Gems from source, then using gems to
2042 install Rails. That worked fine and I've had no problem with the
2043 setup. I suspect this all works out of the box on Breezy.
2045 For my homework assignment, I rewrote in Ruby a little program that
2046 I wrote last week for spam filtering. I suddenly started getting a
2047 lot more spam with unprintable characters in the subject, so I
2048 wanted a program to calculate how many characters in a set of
2049 strings was printable vs. unprintable. I tried at first to write it
2050 in Python, but it turned out Python doesn't have any easy way to do
2051 the equivalent of C's "isprint" test. Eventually I gave up and wrote
2052 it in C, which was really easy.
2054 Googling, it turns out Ruby doesn't have a way to do isprint()
2055 either. :-( But I did find a way to delete all unprintable characters
2056 from a string, so I wrote it using that. (I think Python has that too,
2057 so I could probably go back and write it in Python the same way.)
2059 #!/usr/local/bin/ruby
2061 # This program checks its runtime arguments for number of
2062 # printable and unprintable characters.
2064 class SmartString < String
2065   def print_unprint()
2066     toprint = self.gsub(/[^[:print:]]/, '')
2067     return [toprint.length, self.length - toprint.length]
2068   end
2071 # main: loop over each input word
2073 total_printable = 0
2074 total_unprintable = 0
2075 ARGV.each do |word|
2076   p_u = SmartString.new(word).print_unprint()
2077   total_printable += p_u[0]
2078   total_unprintable += p_u[1]
2081 print "Total: ", total_printable, " printable, ",
2082       total_unprintable, " unprintable\n"
2084 You said to analyze part of the code, so I'll analyze the class
2085 SmartString. I made it a new class that inherits from the normal
2086 String class, so that I could use all the built-in string methods.
2087 Eventually I'd probably want to add some other tests (e.g. checking
2088 how much punctuation and numbers there is compared to letters, maybe
2089 checking word length) but right now the only new method is a
2090 function called print_unprint that returns an array of two items:
2091 the number of printable characters in the string, and the number of
2092 unprintable characters.
2094 It does that by replacing (using gsub, which does a global
2095 substitution over the string) any unprintable character in the string
2096 with '' (i.e. deleting it). It turns out Ruby has a character class
2097 called [:print:] (the character classes are listed on p. 72 of the
2098 second edition of Programming Ruby) so [^[:print:]] matches any
2099 character that's not printable. (I found that snippet by googling.
2100 There are lots of useful Ruby snippets on the web if you google for
2101 terms related to what you're trying to do.)
2103 I confess I'm not 100% clear on the two sets of brackets: the outside
2104 set says "for this regular expression, use any character in this
2105 group" and I grok that, but the inner set with the colons, [::],
2106 seems to be something you always put around character classes
2107 but I'm not comfortable enough yet with the syntax to be sure why.
2109 The return in print_unprint uses [ ] to build up a two-element array
2110 on the fly, so it can return both the printable and unprintable counts.
2111 Then the caller can index the printable count with [0] and the
2112 unprintable count with [1]. If I were actually using this for a
2113 spam filter, instead of printing the count I'd exit with a nonzero
2114 status if there were too many unprintables.
2116         ...Akkana
2118 From laurel.fan@gmail.com  Thu Nov 17 10:34:56 2005
2119 Return-Path: <laurel.fan@gmail.com>
2120 X-Original-To: courses@linuxchix.org
2121 Delivered-To: courses@linuxchix.org
2122 Received: from localhost (localhost [127.0.0.1])
2123         by www.linuxchix.org (Postfix) with ESMTP id D7614273211
2124         for <courses@linuxchix.org>; Thu, 17 Nov 2005 10:34:55 +1100 (EST)
2125 Received: from www.linuxchix.org ([127.0.0.1])
2126         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
2127         id 25687-06 for <courses@linuxchix.org>;
2128         Thu, 17 Nov 2005 10:34:55 +1100 (EST)
2129 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.196])
2130         by www.linuxchix.org (Postfix) with ESMTP id E265B273210
2131         for <courses@linuxchix.org>; Thu, 17 Nov 2005 10:34:54 +1100 (EST)
2132 Received: by xproxy.gmail.com with SMTP id s9so1190752wxc
2133         for <courses@linuxchix.org>; Wed, 16 Nov 2005 15:34:52 -0800 (PST)
2134 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
2135         h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
2136         b=ZP+3r4XV+x7kIrOvUCBkPG7+7n89bkUS7MRLCNTV8RH+yzdeGyK+mWdbRbh79EhBO8VqW8GgcTIMSsovfyxgdLIaPbGUuCJqEPrccv6PMDu/eNsjBoi4G52N37vz1nR2fdWHdtvlTJ1C/2SmyboHj4yMWwrIZIVlEV5DH/Sf3dA=
2137 Received: by 10.70.60.17 with SMTP id i17mr4283429wxa;
2138         Wed, 16 Nov 2005 15:28:02 -0800 (PST)
2139 Received: by 10.70.94.2 with HTTP; Wed, 16 Nov 2005 15:28:02 -0800 (PST)
2140 Message-ID: <8b1e030f0511161528q264be403vef4c54975fe41d1c@mail.gmail.com>
2141 Date: Wed, 16 Nov 2005 15:28:02 -0800
2142 From: Laurel Fan <laurel.fan@gmail.com>
2143 To: courses@linuxchix.org
2144 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
2145         and your first homework assignment
2146 In-Reply-To: <20051109201221.GA9900@shallowsky.com>
2147 MIME-Version: 1.0
2148 Content-Type: text/plain; charset=ISO-8859-1
2149 Content-Transfer-Encoding: quoted-printable
2150 Content-Disposition: inline
2151 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
2152         <20051109201221.GA9900@shallowsky.com>
2153 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
2154 X-Topics: Introduction to Ruby
2155 X-BeenThere: courses@linuxchix.org
2156 X-Mailman-Version: 2.1.5
2157 Precedence: list
2158 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
2159 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2160         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
2161 List-Archive: <http://linuxchix.org/pipermail/courses>
2162 List-Post: <mailto:courses@linuxchix.org>
2163 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
2164 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2165         <mailto:courses-request@linuxchix.org?subject=subscribe>
2166 X-List-Received-Date: Wed, 16 Nov 2005 23:34:56 -0000
2167 Content-Length: 4812
2168 Lines: 111
2170 On 11/9/05, Akkana Peck <akkana@shallowsky.com> wrote:
2171 > Hi!
2173 Hi Akkana!
2175 > For my homework assignment, I rewrote in Ruby a little program that
2176 > I wrote last week for spam filtering. I suddenly started getting a
2177 > lot more spam with unprintable characters in the subject, so I
2178 > wanted a program to calculate how many characters in a set of
2179 > strings was printable vs. unprintable. I tried at first to write it
2180 > in Python, but it turned out Python doesn't have any easy way to do
2181 > the equivalent of C's "isprint" test. Eventually I gave up and wrote
2182 > it in C, which was really easy.
2184 > Googling, it turns out Ruby doesn't have a way to do isprint()
2185 > either. :-( But I did find a way to delete all unprintable characters
2186 > from a string, so I wrote it using that. (I think Python has that too,
2187 > so I could probably go back and write it in Python the same way.)
2189 > #!/usr/local/bin/ruby
2191 > # This program checks its runtime arguments for number of
2192 > # printable and unprintable characters.
2194 > class SmartString < String
2195 >   def print_unprint()
2196 >     toprint =3D self.gsub(/[^[:print:]]/, '')
2197 >     return [toprint.length, self.length - toprint.length]
2198 >   end
2199 > end
2201 > # main: loop over each input word
2203 > total_printable =3D 0
2204 > total_unprintable =3D 0
2205 > ARGV.each do |word|
2206 >   p_u =3D SmartString.new(word).print_unprint()
2207 >   total_printable +=3D p_u[0]
2208 >   total_unprintable +=3D p_u[1]
2209 > end
2211 > print "Total: ", total_printable, " printable, ",
2212 >       total_unprintable, " unprintable\n"
2214 > You said to analyze part of the code, so I'll analyze the class
2215 > SmartString. I made it a new class that inherits from the normal
2216 > String class, so that I could use all the built-in string methods.
2217 > Eventually I'd probably want to add some other tests (e.g. checking
2218 > how much punctuation and numbers there is compared to letters, maybe
2219 > checking word length) but right now the only new method is a
2220 > function called print_unprint that returns an array of two items:
2221 > the number of printable characters in the string, and the number of
2222 > unprintable characters.
2224 You could have done this by extending the String class itself (in the
2225 context of your program only, of course).  We'll learn how later.
2227 > It does that by replacing (using gsub, which does a global
2228 > substitution over the string) any unprintable character in the string
2229 > with '' (i.e. deleting it). It turns out Ruby has a character class
2230 > called [:print:] (the character classes are listed on p. 72 of the
2231 > second edition of Programming Ruby) so [^[:print:]] matches any
2232 > character that's not printable. (I found that snippet by googling.
2233 > There are lots of useful Ruby snippets on the web if you google for
2234 > terms related to what you're trying to do.)
2236 The character classes supported by Ruby are actually standard POSIX
2237 character sets, and I think they work in othe rplaces like Perl,
2238 Python, Java, etc...
2240 > I confess I'm not 100% clear on the two sets of brackets: the outside
2241 > set says "for this regular expression, use any character in this
2242 > group" and I grok that, but the inner set with the colons, [::],
2243 > seems to be something you always put around character classes
2244 > but I'm not comfortable enough yet with the syntax to be sure why.
2246 It's just what the regular expression thing does.  It's a way of
2247 making the difference between "the character class isprint" and "match
2248 the characters i, s, p, r..." really obvious.  I don't know of any
2249 reason they chose that exact syntax, but I'm not a regex expert.  The
2250 character classes are pretty standard.
2252 > The return in print_unprint uses [ ] to build up a two-element array
2253 > on the fly, so it can return both the printable and unprintable counts.
2254 > Then the caller can index the printable count with [0] and the
2255 > unprintable count with [1]. If I were actually using this for a
2256 > spam filter, instead of printing the count I'd exit with a nonzero
2257 > status if there were too many unprintables.
2259 Looks good, and good analysis!  In the more-than-one-way department,
2260 you could have used the String.scan function, documented here:
2261 http://www.ruby-doc.org/core/classes/String.html#M001414
2263 You would want something like:
2264 input.scan(/[[:isprint:]]/).length
2266 scan returns an array of matches, so to count the matches we're
2267 calling length on the array it returns.
2269 String.count also does something close to what you want (but it
2270 wouldn't work here because it can't take a regular expression).  See
2271 http://www.ruby-doc.org/core/classes/String.html#M001414
2273 One of the philosophies of Ruby is that things should be made easy by
2274 making library functions for common tasks (even if it would have taken
2275 only 3 lines to do it the "normal" way).  There are lots of useful
2276 little functions like this scattered around the builtin classes.
2279 Laurel Fan
2280 http://dreadnought.gorgorg.org
2282 From kproot@nerim.net  Thu Nov 10 09:11:08 2005
2283 Return-Path: <kproot@nerim.net>
2284 X-Original-To: courses@linuxchix.org
2285 Delivered-To: courses@linuxchix.org
2286 Received: from localhost (localhost [127.0.0.1])
2287         by www.linuxchix.org (Postfix) with ESMTP id F36A127320C
2288         for <courses@linuxchix.org>; Thu, 10 Nov 2005 09:11:07 +1100 (EST)
2289 Received: from www.linuxchix.org ([127.0.0.1])
2290         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
2291         id 24424-10 for <courses@linuxchix.org>;
2292         Thu, 10 Nov 2005 09:11:07 +1100 (EST)
2293 Received: from kellthuzad.dmz.nerim.net (smtp-dmz-233-wednesday.dmz.nerim.net
2294         [195.5.254.233])
2295         by www.linuxchix.org (Postfix) with ESMTP id 7466E27320B
2296         for <courses@linuxchix.org>; Thu, 10 Nov 2005 09:11:07 +1100 (EST)
2297 Received: from kraid.nerim.net (smtp-103-wednesday.nerim.net [62.4.16.103])
2298         by kellthuzad.dmz.nerim.net (Postfix) with ESMTP id EC7343C15A
2299         for <courses@linuxchix.org>; Wed,  9 Nov 2005 23:10:53 +0100 (CET)
2300 Received: from gelydh (jdelvare.net2.nerim.net [213.41.131.98])
2301         by kraid.nerim.net (Postfix) with ESMTP id 0E1DD40ED9
2302         for <courses@linuxchix.org>; Wed,  9 Nov 2005 23:10:54 +0100 (CET)
2303 Date: Wed, 9 Nov 2005 23:12:35 +0100
2304 From: Karine Delvare <kproot@nerim.net>
2305 To: courses@linuxchix.org
2306 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References, and your
2307         first homework assignment
2308 Message-Id: <20051109231235.863f31fd.kproot@nerim.net>
2309 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
2310 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
2311 X-Mailer: Sylpheed version 2.1.4 (GTK+ 2.6.10; i686-pc-linux-gnu)
2312 Mime-Version: 1.0
2313 Content-Type: text/plain; charset=US-ASCII
2314 Content-Transfer-Encoding: 7bit
2315 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
2316 X-Topics: Introduction to Ruby
2317 X-BeenThere: courses@linuxchix.org
2318 X-Mailman-Version: 2.1.5
2319 Precedence: list
2320 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
2321 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2322         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
2323 List-Archive: <http://linuxchix.org/pipermail/courses>
2324 List-Post: <mailto:courses@linuxchix.org>
2325 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
2326 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2327         <mailto:courses-request@linuxchix.org?subject=subscribe>
2328 X-List-Received-Date: Wed, 09 Nov 2005 22:11:08 -0000
2329 Content-Length: 1636
2330 Lines: 40
2333 Hello! I'm Karine Delvare, french, 27 years old, working as a software
2334 engineer mainly on web application. I have learned and used several
2335 programming languages during my studies and at my jobplaces: C, C++,
2336 C#, a bit of Java, a lot of PHP, Perl. I like object-oriented programming very much, but learned to pay attention to lightness. Now I mostly use PHP at work and C (with GObject) at home, and I remember with a smile the huge slow apps I wrote when .NET was "in"...
2338 I am interested in Ruby out of curiosity. Many times I've been proven
2339 wrong on what I thought was carved in stone about programming languages
2340 and their mechanics, so I would like to have a look at as many as
2341 possible to be able to compare. There is no special task I would like
2342 to do with it, I'll just follow the assignments and maybe I'll come up
2343 with something later on.
2345 I played with tictactoe.rb, found on RubyForge. Here is a sample of
2346 code:
2348 # P1 Turn
2349         puts "Player 1's turn"
2350         puts "Select your space, enter the number that is in the space
2351 you want" disp_board(numspac)
2352         space = gets.to_i # Get the space they want!
2354         while barr[space] != " "
2355                 puts "Try again that one is taken!!!"
2356                 disp_board(numspac)
2357                 space = gets.to_i
2358         end
2359         barr[space] = "X"
2360 # End of Turn
2361 disp_board(barr)
2362 check3row(barr)
2363 # P2 Turn
2364 [...]
2366 Simple code with some input/output: asks the player where he wants to
2367 play, check whether the space is free, display the updated board, check
2368 if someone won. I don't understand the details of each line yet, but
2369 Ruby seems like pretty east to read.
2371 Karine.
2373 From rsvidal@terra.com.br  Sat Nov 12 12:58:38 2005
2374 Return-Path: <rsvidal@terra.com.br>
2375 X-Original-To: courses@linuxchix.org
2376 Delivered-To: courses@linuxchix.org
2377 Received: from localhost (localhost [127.0.0.1])
2378         by www.linuxchix.org (Postfix) with ESMTP id 9091027320E
2379         for <courses@linuxchix.org>; Sat, 12 Nov 2005 12:58:38 +1100 (EST)
2380 Received: from www.linuxchix.org ([127.0.0.1])
2381         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
2382         id 10593-04 for <courses@linuxchix.org>;
2383         Sat, 12 Nov 2005 12:58:38 +1100 (EST)
2384 X-Greylist: delayed 133710 seconds by postgrey-1.21 at nest;
2385         Sat, 12 Nov 2005 12:58:15 EST
2386 Received: from paiol.terra.com.br (paiol.terra.com.br [200.176.10.210])
2387         by www.linuxchix.org (Postfix) with ESMTP id 0065D2731FC
2388         for <courses@linuxchix.org>; Sat, 12 Nov 2005 12:58:15 +1100 (EST)
2389 Received: from linares.terra.com.br (linares.terra.com.br [200.176.10.195])
2390         by paiol.terra.com.br (Postfix) with ESMTP id 563AEEB3C3C
2391         for <courses@linuxchix.org>; Thu, 10 Nov 2005 10:49:46 -0200 (BRST)
2392 Received: from licasi.terra.com.br (licasi.terra.com.br [200.176.10.3])
2393         by linares.terra.com.br (Postfix) with ESMTP id 562AD4DC12A
2394         for <courses@linuxchix.org>; Thu, 10 Nov 2005 10:49:26 -0200 (BRST)
2395 X-Terra-Karma: 0%
2396 X-Terra-Hash: dc04ad9b755c8f35c1198efcd3945767
2397 Received-SPF: pass (licasi.terra.com.br: domain of terra.com.br designates
2398         200.176.10.3 as permitted sender) client-ip=200.176.10.3;
2399         envelope-from=rsvidal@terra.com.br; helo=terra.com.br; 
2400 Received: from terra.com.br (guaiba.terra.com.br [200.176.3.186])
2401         (authenticated user rsvidal)
2402         by licasi.terra.com.br (Postfix) with ESMTP id 7EEB010F02CE
2403         for <courses@linuxchix.org>; Thu, 10 Nov 2005 10:49:23 -0200 (BRST)
2404 Date: Thu, 10 Nov 2005 09:49:23 -0300
2405 Message-Id: <IPQOYB$97CA6D64401B2B48CBBCC8635F7CCDA4@terra.com.br>
2406 Subject: =?iso-8859-1?b?UmU6IFtDb3Vyc2VzXSBbUnVieV0gTGVzc29uIDA6IEluc3RhbGxp?=
2407         =?iso-8859-1?b?bmcsIFJlZmVyZW5jZXMsIGFuZCB5b3VyIGZpcnN0IGhvbWV3b3Jr?=
2408         =?iso-8859-1?b?IGFzc2lnbm1lbnQ=?=
2409 MIME-Version: 1.0
2410 X-Sensitivity: 3
2411 From: "Renata Vidal" <rsvidal@terra.com.br>
2412 To: "courses" <courses@linuxchix.org>
2413 X-XaM3-API-Version: 4.1 (B108)
2414 X-SenderIP: 200.176.1.58
2415 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
2416 Content-Type: text/plain; charset=iso-8859-1
2417 Content-Transfer-Encoding: quoted-printable
2418 X-Content-Filtered-By: Mailman/MimeDel 2.1.5
2419 X-BeenThere: courses@linuxchix.org
2420 X-Mailman-Version: 2.1.5
2421 Precedence: list
2422 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
2423 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2424         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
2425 List-Archive: <http://linuxchix.org/pipermail/courses>
2426 List-Post: <mailto:courses@linuxchix.org>
2427 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
2428 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2429         <mailto:courses-request@linuxchix.org?subject=subscribe>
2430 X-List-Received-Date: Sat, 12 Nov 2005 01:58:38 -0000
2431 Content-Length: 5296
2432 Lines: 129
2436 I just deleted the Joe's mail, but I would like to know what means the co=
2437 mmand "a,b=3D"
2439 I will introduce myself soon, because I didnt my homework yet.
2441 Thanks,
2443 Renata
2444 De:courses-bounces@linuxchix.org
2446 Para:courses@linuxchix.org
2448 C=F3pia:
2450 Data:Wed, 9 Nov 2005 12:12:21 -0800
2452 Assunto:Re: [Courses] [Ruby] Lesson 0: Installing, References, and your f=
2453 irst homework assignment
2455 > Hi! Laurel, thanks for running the course.
2457 > I'm a longtime programmer in lots of languages. My two favorites
2458 > are C and Python; I suppose because they're simple, compact and
2459 > efficient. I've used Ruby and Rails a little bit, but I want to
2460 > learn more about Ruby because although I can get by in it, I
2461 > don't feel like I understand it as well as I'd like to.
2463 > I expect most of my Ruby use will be for Rails, but who knows?
2464 > Maybe the course will convince me that I should use it instead of
2465 > Python for writing standalone scripts. And every language has
2466 > strengths and weaknesses, so even if I don't switch to Ruby as
2467 > my main scripting language, I'm sure there will be times when it's
2468 > the best tool for the job.
2470 > Laurel Fan writes:
2471 > > Any modern Linux distribution has ruby package(s). It might even
2472 > > already be installed. (To check, try 'ruby --version' in a shell). If=
2475 > I'm currently running Ubuntu "Hoary Hedgehog". Although it offers
2476 > Ruby packages (which are probably fine for this course), I didn't
2477 > have much luck getting Rails and Gems to work, even after adding the
2478 > backports from Breezy. Also, the built-in Ruby didn't install a
2479 > "ruby" command so I had to make a symlink (I notice someone else
2480 > just asked about that on newchix recently).
2482 > I ended up building Ruby and Gems from source, then using gems to
2483 > install Rails. That worked fine and I've had no problem with the
2484 > setup. I suspect this all works out of the box on Breezy.
2486 > For my homework assignment, I rewrote in Ruby a little program that
2487 > I wrote last week for spam filtering. I suddenly started getting a
2488 > lot more spam with unprintable characters in the subject, so I
2489 > wanted a program to calculate how many characters in a set of
2490 > strings was printable vs. unprintable. I tried at first to write it
2491 > in Python, but it turned out Python doesn't have any easy way to do
2492 > the equivalent of C's "isprint" test. Eventually I gave up and wrote
2493 > it in C, which was really easy.
2495 > Googling, it turns out Ruby doesn't have a way to do isprint()
2496 > either. :-( But I did find a way to delete all unprintable characters
2497 > from a string, so I wrote it using that. (I think Python has that too,
2498 > so I could probably go back and write it in Python the same way.)
2500 > #!/usr/local/bin/ruby
2502 > # This program checks its runtime arguments for number of
2503 > # printable and unprintable characters.
2505 > class SmartString < String
2506 > def print_unprint()
2507 > toprint =3D self.gsub(/[^[:print:]]/, '')
2508 > return [toprint.length, self.length - toprint.length]
2509 > end
2510 > end
2512 > # main: loop over each input word
2514 > total_printable =3D 0
2515 > total_unprintable =3D 0
2516 > ARGV.each do |word|
2517 > p_u =3D SmartString.new(word).print_unprint()
2518 > total_printable +=3D p_u[0]
2519 > total_unprintable +=3D p_u[1]
2520 > end
2522 > print "Total: ", total_printable, " printable, ",
2523 > total_unprintable, " unprintable\n"
2525 > You said to analyze part of the code, so I'll analyze the class
2526 > SmartString. I made it a new class that inherits from the normal
2527 > String class, so that I could use all the built-in string methods.
2528 > Eventually I'd probably want to add some other tests (e.g. checking
2529 > how much punctuation and numbers there is compared to letters, maybe
2530 > checking word length) but right now the only new method is a
2531 > function called print_unprint that returns an array of two items:
2532 > the number of printable characters in the string, and the number of
2533 > unprintable characters.
2535 > It does that by replacing (using gsub, which does a global
2536 > substitution over the string) any unprintable character in the string
2537 > with '' (i.e. deleting it). It turns out Ruby has a character class
2538 > called [:print:] (the character classes are listed on p. 72 of the
2539 > second edition of Programming Ruby) so [^[:print:]] matches any
2540 > character that's not printable. (I found that snippet by googling.
2541 > There are lots of useful Ruby snippets on the web if you google for
2542 > terms related to what you're trying to do.)
2544 > I confess I'm not 100% clear on the two sets of brackets: the outside
2545 > set says "for this regular expression, use any character in this
2546 > group" and I grok that, but the inner set with the colons, [::],
2547 > seems to be something you always put around character classes
2548 > but I'm not comfortable enough yet with the syntax to be sure why.
2550 > The return in print_unprint uses [ ] to build up a two-element array
2551 > on the fly, so it can return both the printable and unprintable counts.=
2553 > Then the caller can index the printable count with [0] and the
2554 > unprintable count with [1]. If I were actually using this for a
2555 > spam filter, instead of printing the count I'd exit with a nonzero
2556 > status if there were too many unprintables.
2558 > ...Akkana
2559 > _______________________________________________
2560 > Courses mailing list
2561 > Courses@linuxchix.org
2562 > http://mailman.linuxchix.org/mailman/listinfo/courses
2564 From laurel.fan@gmail.com  Thu Nov 17 02:21:10 2005
2565 Return-Path: <laurel.fan@gmail.com>
2566 X-Original-To: courses@linuxchix.org
2567 Delivered-To: courses@linuxchix.org
2568 Received: from localhost (localhost [127.0.0.1])
2569         by www.linuxchix.org (Postfix) with ESMTP id 69BD2273210
2570         for <courses@linuxchix.org>; Thu, 17 Nov 2005 02:21:10 +1100 (EST)
2571 Received: from www.linuxchix.org ([127.0.0.1])
2572         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
2573         id 22839-07 for <courses@linuxchix.org>;
2574         Thu, 17 Nov 2005 02:21:10 +1100 (EST)
2575 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.195])
2576         by www.linuxchix.org (Postfix) with ESMTP id 84C8C27320D
2577         for <courses@linuxchix.org>; Thu, 17 Nov 2005 02:21:09 +1100 (EST)
2578 Received: by xproxy.gmail.com with SMTP id s9so1094458wxc
2579         for <courses@linuxchix.org>; Wed, 16 Nov 2005 07:21:05 -0800 (PST)
2580 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
2581         h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
2582         b=jvNF83R8VeZeQaHjGg9//w9olDGjskcEaQC2xkM1K2EMEm0sm7RWvyCLrfEDb5Gr7ZgCtPQyGf6fRw3NvqQiiPDFMosUxpIPgnRcqi+UkDOpq7YxGfLQtHtXBCTH8qeYa2+IDcb4pgPhnBWYSj3HpDCQvVV53dHtsLYlP7FabK4=
2583 Received: by 10.70.60.5 with SMTP id i5mr4004555wxa;
2584         Wed, 16 Nov 2005 07:21:05 -0800 (PST)
2585 Received: by 10.70.94.2 with HTTP; Wed, 16 Nov 2005 07:21:05 -0800 (PST)
2586 Message-ID: <8b1e030f0511160721mc4fd7e1u768e3e027b0c04c4@mail.gmail.com>
2587 Date: Wed, 16 Nov 2005 07:21:05 -0800
2588 From: Laurel Fan <laurel.fan@gmail.com>
2589 To: courses@linuxchix.org
2590 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
2591         and your first homework assignment
2592 In-Reply-To: <4371C028.8020606@antenna.nl>
2593 MIME-Version: 1.0
2594 Content-Type: text/plain; charset=ISO-8859-1
2595 Content-Transfer-Encoding: quoted-printable
2596 Content-Disposition: inline
2597 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
2598         <4371C028.8020606@antenna.nl>
2599 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
2600 X-Topics: Introduction to Ruby
2601 X-BeenThere: courses@linuxchix.org
2602 X-Mailman-Version: 2.1.5
2603 Precedence: list
2604 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
2605 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2606         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
2607 List-Archive: <http://linuxchix.org/pipermail/courses>
2608 List-Post: <mailto:courses@linuxchix.org>
2609 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
2610 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2611         <mailto:courses-request@linuxchix.org?subject=subscribe>
2612 X-List-Received-Date: Wed, 16 Nov 2005 15:21:10 -0000
2613 Content-Length: 3029
2614 Lines: 106
2616 reply to chantal
2618 On 11/9/05, Chantal Rosmuller <chantal@antenna.nl> wrote:
2619 > Hi I'm Chantal
2623 > Well anyway, here's my
2624 > homework, some code I wrote myself, I needed to configure an interface
2625 > on an openbsd system for a whole ip range and it had to put something
2626 > like this:
2628 > inet alias x.y.z.1 255.255.255.0
2629 > inet alias x.y.z.2 255.255.255.0
2631 > etc
2633 > I didn't want to type all of that so I wrote ipspitter.rb:
2634 > It basically takes a number to start with and adds one a number of times
2635 > and keeps printing that, together with a string for the first three
2636 > parts of the ip address and some text if you want
2638 This looks great, a few comments (for you and everyone else) in-line:
2640 > #!/usr/bin/ruby
2642 > puts "This is ipspitter"
2643 > puts "Which number do you want to start the range with?"
2645 > count =3D gets.to_i
2647 puts prints a string (I think it stands for "PUT String"), and gets
2648 (conincidentally enough) gets a string.  It defaults to getting it
2649 from standard input/output (which is the terminal if you're running
2650 the program in the shell without redirecting input), but you can make
2651 it put/get input from any IO object, like a file, network socket, etc
2652 (see the IO documentation for more).
2654 > sum =3D count
2656 It doesn't look like you use sum.. maybe leftover from a previous
2657 incarnation of the program?
2659 > puts " How many ip addresses do you want?"
2661 > number =3D gets.to_i
2662 > number =3D number - 1
2663 > puts "Enter the first three parts of the ip-address (for example
2664 > 192.168.4. )"
2665 > range =3D gets.chomp
2667 Chomp is like chomp in perl;  it takes the newline off the end of the
2668 string if it happens to have one.
2670 > puts "Do you want to put some text in front of the ip-address? Put it her=
2672 > textbefore =3D gets.chomp
2674 > puts "Do you want to put some text after the ip-address? Put it here"
2675 > textafter =3D gets
2677 > puts textbefore + range + count.to_s + textafter
2679 > number.times do
2680 >         count +=3D1
2681 >         sum +=3D count
2682 >         puts textbefore + range + count.to_s + textafter
2683 > end
2685 There are a few ways to rearrange the loop that might (or might not be) cle=
2686 arer.
2688 First, if you take away the 'number =3D number-1' line, I think you
2689 could also take away the first puts outside of the loop, and do:
2691 number.times do
2692   puts textbefore + range + count.to_s + textafter
2693   count +=3D1
2694   sum +=3D count
2697 Or, you could do something like this (which we'll learn about mostly
2698 in Lesson 2 in the Expressions chapter of the book):
2700 start =3D count
2701 end =3D count + number - 1
2702 start.upto(end) do |current_number|
2703   puts textbefore + range + current_number.to_s + textafter
2706 (I haven't tried it so there's probably an off by one error)
2708 The upto method (in the Integer class) does the stuff in the do/end
2709 for every integer from start up to end.
2711 Also, a different way to create strings:  This code would do the same thing=
2714 puts "#{textbefore}#{range}#{count}#{textafter}"
2716 (and it would call the count.to_s for you).  We'll see this first in Lesson=
2717  1.
2720 Laurel Fan
2721 http://dreadnought.gorgorg.org
2723 From wallachd@earthlink.net  Mon Nov 28 09:46:25 2005
2724 Return-Path: <wallachd@earthlink.net>
2725 X-Original-To: courses@linuxchix.org
2726 Delivered-To: courses@linuxchix.org
2727 Received: from localhost (localhost [127.0.0.1])
2728         by www.linuxchix.org (Postfix) with ESMTP id CB90227321C
2729         for <courses@linuxchix.org>; Mon, 28 Nov 2005 09:46:25 +1100 (EST)
2730 Received: from www.linuxchix.org ([127.0.0.1])
2731         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
2732         id 17529-03 for <courses@linuxchix.org>;
2733         Mon, 28 Nov 2005 09:46:25 +1100 (EST)
2734 X-Greylist: delayed 323 seconds by postgrey-1.21 at nest;
2735         Mon, 28 Nov 2005 09:46:25 EST
2736 Received: from fall-lakeland.atl.sa.earthlink.net
2737         (fall-lakeland.atl.sa.earthlink.net [207.69.195.103])
2738         by www.linuxchix.org (Postfix) with ESMTP id 096422731F6
2739         for <courses@linuxchix.org>; Mon, 28 Nov 2005 09:46:25 +1100 (EST)
2740 Received: from pop-cowbird.atl.sa.earthlink.net ([207.69.195.68])
2741         by fall-lakeland.atl.sa.earthlink.net with esmtp (Exim 4.34)
2742         id 1EgVCi-0000bV-C9
2743         for courses@linuxchix.org; Sun, 27 Nov 2005 17:41:04 -0500
2744 Received: from user-2ivfl2i.dialup.mindspring.com ([165.247.212.82])
2745         by pop-cowbird.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
2746         id 1EgVCS-00025T-00
2747         for courses@linuxchix.org; Sun, 27 Nov 2005 17:40:48 -0500
2748 Message-ID: <438A35EF.4080805@earthlink.net>
2749 Date: Sun, 27 Nov 2005 14:40:47 -0800
2750 From: Darlene Wallach <wallachd@earthlink.net>
2751 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US;
2752         rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1
2753 X-Accept-Language: en-us, en, he
2754 MIME-Version: 1.0
2755 To: courses@linuxchix.org
2756 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References, and your first
2757         homework assignment
2758 References: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
2759 In-Reply-To: <8b1e030f0511071730h913dc2i317f106953802781@mail.gmail.com>
2760 Content-Type: text/plain; charset=us-ascii; format=flowed
2761 Content-Transfer-Encoding: 7bit
2762 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
2763 X-Topics: Introduction to Ruby
2764 X-BeenThere: courses@linuxchix.org
2765 X-Mailman-Version: 2.1.5
2766 Precedence: list
2767 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
2768 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2769         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
2770 List-Archive: <http://linuxchix.org/pipermail/courses>
2771 List-Post: <mailto:courses@linuxchix.org>
2772 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
2773 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2774         <mailto:courses-request@linuxchix.org?subject=subscribe>
2775 X-List-Received-Date: Sun, 27 Nov 2005 22:46:26 -0000
2776 Content-Length: 2885
2777 Lines: 79
2779 Laurel Fan wrote:
2780 > = Lesson 0: Installing and Documentation References
2781 [snip]
2782 > == Homework
2783 [snip]
2785 > First, introduce yourself.  Do you know any other programming
2786 > languages?  What do you like/not like about them?  Why are you
2787 > interested in Ruby?  What are some things you'd like to learn to do?
2792 Laurel - thank you for the Ruby course!
2794 My name is Darlene. I'm getting a late start on the Ruby course.
2795 I'm an unemployed software engineer who did most of my work using
2796 "C" and korn shell scripts.
2798 I used to be very passionate about software but since returning
2799 from almost 2 months in Palestine in 2002, I've been more passionate
2800 about Palestine and other related political issues. I'm trying to
2801 get my feet back in the software arena.
2803 I heard good things about Ruby and kind of got an introduction last year 
2804 with a hands-on Ruby track with the Silicon Valley Patterns group. I'm 
2805 interested in learning Ruby and using it. I'm recently read Ruby on 
2806 Rails articles in the Linux Journal by Reuven Lerner. Rails seems very 
2807 impressive too.
2809 > Second, find and run any ruby program.  It can be something you wrote,
2810 > something you downloaded (hint, look on RubyForge), an example you
2811 > copied out of a book, something a friend wrote for you, etc.
2813 > Finally, look at the code.  Find a section of about 5-20 lines of
2814 > code, and try to figure out what it does.  If you figure it out (or
2815 > just have a good guess), explain it to us.  If not, show us the code
2816 > and we'll try to explain it.
2819 Here is one of the ruby scripts from execises during the Ruby track
2820 last year:
2821 # Define a method named "even" which takes one argument, an array of
2822 # integers, and which returns an array consisting of the even integers
2823 # (if any) from the argument array.
2825 class ExerciseE
2826          def even(startArray)
2827            evenArray = Array.new()
2828            startArray.each do |x|
2829              if (x % 2) == 0
2830                evenArray.push(x)
2831              end
2832            end
2833            return evenArray
2834          end
2838 -- 
2839 World Centric Fair Trade & Eco Store
2840 http://www.worldcentric.org/store/
2841 We have created and live in a world of gross social
2842 and economic inequalities[1] and are at the same
2843 time severely impacting[2] the natural eco-systems
2844 and regenerating bio-capacity of the planet. Our
2845 every action has an impact on the well-being of our
2846 planet and our everyday decisions[3] can help create
2847 a better world for all. In keeping with this fact
2848 and our vision, the World Centric Fair Trade/Eco
2849 Online Store provides everyday consumption choices,
2850 which can help minimize social & economic
2851 inequalities, reduce the impact of our consumption
2852 on the environment and help create a better and
2853 sustainable world.
2855 [1] http://www.worldcentric.org/stateworld/socialjustice.htm
2856 [2] http://www.worldcentric.org/stateworld/environment.htm
2857 [3] http://www.worldcentric.org/sustain/index.htm
2859 From anne@wjh.harvard.edu  Sat Nov 12 07:56:57 2005
2860 Return-Path: <anne@wjh.harvard.edu>
2861 X-Original-To: courses@linuxchix.org
2862 Delivered-To: courses@linuxchix.org
2863 Received: from localhost (localhost [127.0.0.1])
2864         by www.linuxchix.org (Postfix) with ESMTP id BC52827320E
2865         for <courses@linuxchix.org>; Sat, 12 Nov 2005 07:56:56 +1100 (EST)
2866 Received: from www.linuxchix.org ([127.0.0.1])
2867         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
2868         id 08763-04 for <courses@linuxchix.org>;
2869         Sat, 12 Nov 2005 07:56:56 +1100 (EST)
2870 X-Greylist: delayed 769 seconds by postgrey-1.21 at nest;
2871         Sat, 12 Nov 2005 07:56:49 EST
2872 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
2873         by www.linuxchix.org (Postfix) with ESMTP id B347027320B
2874         for <courses@linuxchix.org>; Sat, 12 Nov 2005 07:56:49 +1100 (EST)
2875 Received: from localhost (anne@localhost)
2876         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jABKhgg04390
2877         for <courses@linuxchix.org>; Fri, 11 Nov 2005 15:43:42 -0500 (EST)
2878 Date: Fri, 11 Nov 2005 15:43:42 -0500 (EST)
2879 From: Anne G <anne@wjh.harvard.edu>
2880 To: <courses@linuxchix.org>
2881 Subject: [Courses] [Ruby] Lesson 0: Installing
2882 Message-ID: <Pine.SOL.4.30.0511111514190.2986-100000@wjh1.wjh.harvard.edu>
2883 MIME-Version: 1.0
2884 Content-Type: TEXT/PLAIN; charset=US-ASCII
2885 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
2886 X-Topics: Introduction to Ruby
2887 X-BeenThere: courses@linuxchix.org
2888 X-Mailman-Version: 2.1.5
2889 Precedence: list
2890 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
2891 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2892         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
2893 List-Archive: <http://linuxchix.org/pipermail/courses>
2894 List-Post: <mailto:courses@linuxchix.org>
2895 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
2896 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
2897         <mailto:courses-request@linuxchix.org?subject=subscribe>
2898 X-List-Received-Date: Fri, 11 Nov 2005 20:56:57 -0000
2899 Content-Length: 2480
2900 Lines: 81
2904 My name is anne. I have been programming in C and matlab. I
2905 started to learn objective C, but I am really stumped by how
2906 big a step I have to take, and I keep getting mad... How is
2907 this supposed to be the next thing after C. There are way
2908 too much idiosynchratic tricks to learn, I hate the whole
2909 memory management, beginners like me should not have to
2910 deal with it...
2912 So I am delighted to try if rubi will ease the way.
2914 First I just spend hours and hours on the install on my mac.
2915 First, the latest rubi is 1.8.3
2917 I found the source easily enough, but I could not find an
2918 install application for it, and I did not know what to do
2919 with the source. Luckily, I found a blog that saved me,
2920 http://www.downes.ca/cgi-bin/page.cgi?post=31620
2921 I went into the directory in the terminal window, ls ...
2922 than I think I ran
2923 ./configure
2924 make
2925 sudo make install
2926 (I had missed his instruction to become superuser, and got
2927 an error message, permission denied at first).
2929 rubi -v
2930 does give me 1.8.3 version.
2932 the application for rubicocoa was easier to find
2933 http://rubycocoa.sourceforge.net/
2934 I downloaded and installed the one for panther.
2935 When I ran xcode, rubi is one of the options. I don't know
2936 how to tell if it is the right version.
2938 I did not try to install ruby on rails for now.
2940 I found a tutorial on rubycocoa
2941 http://rootprompt.org/article.php3?article=7785
2942 and I am working my way through, but it is beyond what I
2943 want to do right now.
2945 I just want to run some simple code, and I don't know where
2946 to put the code in all the files.
2948 There is a main.m file which I think you don't usually
2949 touch. there is an rb_main.rb file which probably is the one
2950 to use.
2952 require 'osx/cocoa'
2954 def rb_main_init
2955   path =
2956 OSX::NSBundle.mainBundle.resourcePath.fileSystemRepresentation
2957   rbfiles = Dir.entries(path).select {|x| /\.rb\z/ =~ x}
2958   rbfiles -= [ File.basename(__FILE__) ]
2959   rbfiles.each do |path|
2960     require( File.basename(path) )
2961   end
2964 if $0 == __FILE__ then
2965   rb_main_init
2966   OSX.NSApplicationMain(0, nil)
2970 I don't think I need to know what this says, but I do need
2971 to know where to put a rubi instruction, such as type "hello
2972 world"... Does anyone know?
2974 I understand that coco+rubi may be adding more complexity
2975 then I am supposed to have, but I an xcode environment
2976 should be much more pleasant than text files and terminal
2977 window compilation. So if I can figure how to do straight
2978 rubi code and then cocoa code in the same environment, it
2979 seems worth the extra effort
2984 From anne@wjh.harvard.edu  Tue Nov 15 01:10:51 2005
2985 Return-Path: <anne@wjh.harvard.edu>
2986 X-Original-To: courses@linuxchix.org
2987 Delivered-To: courses@linuxchix.org
2988 Received: from localhost (localhost [127.0.0.1])
2989         by www.linuxchix.org (Postfix) with ESMTP id 63B0127320D
2990         for <courses@linuxchix.org>; Tue, 15 Nov 2005 01:10:51 +1100 (EST)
2991 Received: from www.linuxchix.org ([127.0.0.1])
2992         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
2993         id 06384-09 for <courses@linuxchix.org>;
2994         Tue, 15 Nov 2005 01:10:51 +1100 (EST)
2995 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
2996         by www.linuxchix.org (Postfix) with ESMTP id 6D2BF2731FC
2997         for <courses@linuxchix.org>; Tue, 15 Nov 2005 01:10:50 +1100 (EST)
2998 Received: from localhost (anne@localhost)
2999         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jAEEAke26784
3000         for <courses@linuxchix.org>; Mon, 14 Nov 2005 09:10:46 -0500 (EST)
3001 Date: Mon, 14 Nov 2005 09:10:45 -0500 (EST)
3002 From: Anne G <anne@wjh.harvard.edu>
3003 To: <courses@linuxchix.org>
3004 Subject: Re: [Courses] [Ruby] Lesson 0: Homework
3005 In-Reply-To: <Pine.SOL.4.30.0511111514190.2986-100000@wjh1.wjh.harvard.edu>
3006 Message-ID: <Pine.SOL.4.30.0511140853010.25820-100000@wjh1.wjh.harvard.edu>
3007 MIME-Version: 1.0
3008 Content-Type: TEXT/PLAIN; charset=US-ASCII
3009 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3010 X-Topics: Introduction to Ruby
3011 X-BeenThere: courses@linuxchix.org
3012 X-Mailman-Version: 2.1.5
3013 Precedence: list
3014 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3015 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3016         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3017 List-Archive: <http://linuxchix.org/pipermail/courses>
3018 List-Post: <mailto:courses@linuxchix.org>
3019 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3020 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3021         <mailto:courses-request@linuxchix.org?subject=subscribe>
3022 X-List-Received-Date: Mon, 14 Nov 2005 14:10:51 -0000
3023 Content-Length: 2668
3024 Lines: 87
3026 The course web site is back, yeah.
3028 I figured out how to run ruby with rubycocoa. I just add a
3029 ruby file, erase the lines about a class, and enter the ruby
3030 code. It compiles, and prints in the run log window.
3032 Here is my homework. I cheated and found a snipet of
3033 text which makes sense to me, and also has a commentary
3034 http://redhanded.hobix.com/inspect/thinStrandOfSearchAndReplaceRails.html
3035 the snipet was taken from somewhere else, and I added print
3036 to see what it does.
3038 def quicksort( xs )
3039    puts "Iterations, array size = "
3040    puts xs.size
3041    puts "Print the array"
3042    puts xs
3043    return xs if xs.size <= 1
3044    m = xs[0] # Split-Element
3045    quicksort(xs.select { |i| i < m } ) +
3046      xs.select { |i| i == m } +
3047      quicksort(xs.select { |i| i > m } )
3049 puts "Final array"
3050 puts quicksort([13, 11, 74, 69, 0])
3051 puts "hello we are done"
3053 Here is the comment
3054 -----------------------------------------------------------------
3055 line by line:
3057   return xs if xs.size <= 1
3060 If the size is 1 or 0, we just return the array; it's already sorted
3062   m = xs[0]
3064 Here we choose an arbitrary "Pivot" element.
3065 This can be any element of the array. In this case we choose
3066 the first.
3068   quicksort(xs.select { |i| i < m } ) +
3069      xs.select { |i| i == m } +
3070      quicksort(xs.select{ |i| i > m } )
3072 This is a little more complicated. First, let's figure out
3073 what those selects do. The first one selects all elements
3074 less than the pivot. The second selects all elements equal
3075 to the pivot. The final one selects all elements greater
3076 than the pivot. Let's modify this and use some temp variables.
3078   less = xs.select { |i| i < m }
3079   equal = xs.select { |i| i == m }
3080   more = xs.select { |i| i > m }
3082   quicksort( less ) +
3083     equal +
3084     quicksort( more ) )
3087 In other words, we're returning a list of all the elements
3088 less than the pivot, sorted, then all those equal, then all
3089 those greater, sorted. This is classic divide-and-conquer
3090 recursion. Quicksort is applied to ever smaller lists until
3091 we use it on lists of one or zero elements, and we hit the
3092 terminating condition.
3094 -----------------------------------------------------------
3095 the xs.select is equivalent to the find function in matlab.
3097 xs.select { |i| i < m }
3098 |i| must mean for each element of xs compare it to m
3099 what is confustin to me is I usually use i as an index, but
3100 since m=xs[0], i must be an array element.
3102 -----------------------------------------------------------
3103 I have never used recursion like this, it is very efficient,
3104 but I wonder about readability!
3106 Thank you so much for this course. Finding this little
3107 snipet and running it was fun. And it was interesting to see
3108 what others have found
3110 Anne
3114 From laurel.fan@gmail.com  Sat Nov 19 05:18:41 2005
3115 Return-Path: <laurel.fan@gmail.com>
3116 X-Original-To: courses@linuxchix.org
3117 Delivered-To: courses@linuxchix.org
3118 Received: from localhost (localhost [127.0.0.1])
3119         by www.linuxchix.org (Postfix) with ESMTP id E996B273213
3120         for <courses@linuxchix.org>; Sat, 19 Nov 2005 05:18:40 +1100 (EST)
3121 Received: from www.linuxchix.org ([127.0.0.1])
3122         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3123         id 08917-03 for <courses@linuxchix.org>;
3124         Sat, 19 Nov 2005 05:18:40 +1100 (EST)
3125 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.196])
3126         by www.linuxchix.org (Postfix) with ESMTP id 29AC12731F6
3127         for <courses@linuxchix.org>; Sat, 19 Nov 2005 05:18:39 +1100 (EST)
3128 Received: by xproxy.gmail.com with SMTP id s9so227320wxc
3129         for <courses@linuxchix.org>; Fri, 18 Nov 2005 10:18:35 -0800 (PST)
3130 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
3131         h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
3132         b=qLGu5W/Q9LktNuJTJHR/7GIEOKMykqb+sjL0/s7zE1/vgee1GZJMnufuXJnK8aUfxmR2Rz83KKKwbPsvtNpaTkif15WUbR/lTqdrGj8fBJP2KcoysGYPadtOpN7EsweLEAY7Zbsy33inpnx2heRqTL2W9f8pfi2fXKTGUPLEtII=
3133 Received: by 10.70.124.10 with SMTP id w10mr40867wxc;
3134         Fri, 18 Nov 2005 10:18:34 -0800 (PST)
3135 Received: by 10.70.94.2 with HTTP; Fri, 18 Nov 2005 10:18:34 -0800 (PST)
3136 Message-ID: <8b1e030f0511181018peb33855jf6defd132118a54f@mail.gmail.com>
3137 Date: Fri, 18 Nov 2005 10:18:34 -0800
3138 From: Laurel Fan <laurel.fan@gmail.com>
3139 To: Anne G <anne@wjh.harvard.edu>
3140 Subject: Re: [Courses] [Ruby] Lesson 0: Homework
3141 In-Reply-To: <Pine.SOL.4.30.0511140853010.25820-100000@wjh1.wjh.harvard.edu>
3142 MIME-Version: 1.0
3143 Content-Type: text/plain; charset=ISO-8859-1
3144 Content-Transfer-Encoding: quoted-printable
3145 Content-Disposition: inline
3146 References: <Pine.SOL.4.30.0511111514190.2986-100000@wjh1.wjh.harvard.edu>
3147         <Pine.SOL.4.30.0511140853010.25820-100000@wjh1.wjh.harvard.edu>
3148 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3149 X-Topics: Introduction to Ruby
3150 Cc: courses@linuxchix.org
3151 X-BeenThere: courses@linuxchix.org
3152 X-Mailman-Version: 2.1.5
3153 Precedence: list
3154 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3155 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3156         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3157 List-Archive: <http://linuxchix.org/pipermail/courses>
3158 List-Post: <mailto:courses@linuxchix.org>
3159 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3160 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3161         <mailto:courses-request@linuxchix.org?subject=subscribe>
3162 X-List-Received-Date: Fri, 18 Nov 2005 18:18:41 -0000
3163 Content-Length: 3347
3164 Lines: 102
3166 On 11/14/05, Anne G <anne@wjh.harvard.edu> wrote:
3167 Hi Anne!
3169 Great example implementation of quicksort.  It shows off one of the
3170 unique features of ruby, which is the block syntax (the { |i| i < m }
3171 stuff).  There's more about blocks in the book, and this interview
3172 with the language designer (Yukihiro "Matz" Matsumoto) gives a little
3173 more background:
3175 http://www.artima.com/intv/closures.html
3177 > def quicksort( xs )
3178 >    puts "Iterations, array size =3D "
3179 >    puts xs.size
3180 >    puts "Print the array"
3181 >    puts xs
3182 >    return xs if xs.size <=3D 1
3183 >    m =3D xs[0] # Split-Element
3184 >    quicksort(xs.select { |i| i < m } ) +
3185 >      xs.select { |i| i =3D=3D m } +
3186 >      quicksort(xs.select { |i| i > m } )
3187 > end
3188 > puts "Final array"
3189 > puts quicksort([13, 11, 74, 69, 0])
3190 > puts "hello we are done"
3192 > Here is the comment
3193 > -----------------------------------------------------------------
3194 > line by line:
3196 >   return xs if xs.size <=3D 1
3199 > If the size is 1 or 0, we just return the array; it's already sorted
3201 >   m =3D xs[0]
3203 > Here we choose an arbitrary "Pivot" element.
3204 > This can be any element of the array. In this case we choose
3205 > the first.
3207 >   quicksort(xs.select { |i| i < m } ) +
3208 >      xs.select { |i| i =3D=3D m } +
3209 >      quicksort(xs.select{ |i| i > m } )
3211 > This is a little more complicated. First, let's figure out
3212 > what those selects do. The first one selects all elements
3213 > less than the pivot. The second selects all elements equal
3214 > to the pivot. The final one selects all elements greater
3215 > than the pivot. Let's modify this and use some temp variables.
3217 >   less =3D xs.select { |i| i < m }
3218 >   equal =3D xs.select { |i| i =3D=3D m }
3219 >   more =3D xs.select { |i| i > m }
3221 >   quicksort( less ) +
3222 >     equal +
3223 >     quicksort( more ) )
3226 > In other words, we're returning a list of all the elements
3227 > less than the pivot, sorted, then all those equal, then all
3228 > those greater, sorted. This is classic divide-and-conquer
3229 > recursion. Quicksort is applied to ever smaller lists until
3230 > we use it on lists of one or zero elements, and we hit the
3231 > terminating condition.
3233 > -----------------------------------------------------------
3234 > the xs.select is equivalent to the find function in matlab.
3236 > xs.select { |i| i < m }
3237 > |i| must mean for each element of xs compare it to m
3238 > what is confustin to me is I usually use i as an index, but
3239 > since m=3Dxs[0], i must be an array element.
3241 Yes, you're right.  If you use matlab, you might like all the
3242 functions on Enumerable (like select), since they kind of resemble
3243 doing vector operations.
3245 > -----------------------------------------------------------
3246 > I have never used recursion like this, it is very efficient,
3247 > but I wonder about readability!
3249 Sometimes I find it more readable to use the long form, such as:
3251 xs.select do |i|
3252   i < m
3255 In any case, I think it takes some getting used to.  It's not as
3256 immediately intuitive as some concepts (like if/else).  I think there
3257 are lots of cases when it's more readable than doing it without it.=20
3258 When you do a sort in C, and want to define your own comparison
3259 function, you have to define a function separately and make a function
3260 pointer;  in other OO languages like C++ and Java, the same thing
3261 might require making a completely different object.
3266 Laurel Fan
3267 http://dreadnought.gorgorg.org
3269 From anne@wjh.harvard.edu  Fri Nov 18 09:32:29 2005
3270 Return-Path: <anne@wjh.harvard.edu>
3271 X-Original-To: courses@linuxchix.org
3272 Delivered-To: courses@linuxchix.org
3273 Received: from localhost (localhost [127.0.0.1])
3274         by www.linuxchix.org (Postfix) with ESMTP id 1E423273212
3275         for <courses@linuxchix.org>; Fri, 18 Nov 2005 09:32:29 +1100 (EST)
3276 Received: from www.linuxchix.org ([127.0.0.1])
3277         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3278         id 01993-10 for <courses@linuxchix.org>;
3279         Fri, 18 Nov 2005 09:32:29 +1100 (EST)
3280 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
3281         by www.linuxchix.org (Postfix) with ESMTP id 1560927320D
3282         for <courses@linuxchix.org>; Fri, 18 Nov 2005 09:32:27 +1100 (EST)
3283 Received: from localhost (anne@localhost)
3284         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jAHMWJa15531
3285         for <courses@linuxchix.org>; Thu, 17 Nov 2005 17:32:23 -0500 (EST)
3286 Date: Thu, 17 Nov 2005 17:32:19 -0500 (EST)
3287 From: Anne G <anne@wjh.harvard.edu>
3288 To: <courses@linuxchix.org>
3289 Subject: Re: [Courses] [Ruby] Lesson 0: Installing
3290 In-Reply-To: <Pine.SOL.4.30.0511111514190.2986-100000@wjh1.wjh.harvard.edu>
3291 Message-ID: <Pine.SOL.4.30.0511171704380.13651-100000@wjh1.wjh.harvard.edu>
3292 MIME-Version: 1.0
3293 Content-Type: TEXT/PLAIN; charset=US-ASCII
3294 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3295 X-Topics: Introduction to Ruby
3296 X-BeenThere: courses@linuxchix.org
3297 X-Mailman-Version: 2.1.5
3298 Precedence: list
3299 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3300 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3301         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3302 List-Archive: <http://linuxchix.org/pipermail/courses>
3303 List-Post: <mailto:courses@linuxchix.org>
3304 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3305 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3306         <mailto:courses-request@linuxchix.org?subject=subscribe>
3307 X-List-Received-Date: Thu, 17 Nov 2005 22:32:29 -0000
3308 Content-Length: 2786
3309 Lines: 84
3313 I started thinking about lesson 1, but I am spending most of
3314 my time reading about set ups.
3316 I would like to look at ruby class methods, but I have not
3317 figured out how to do that. there is something called ri
3318 which is a terminal program but I have not really figured
3319 out how to use it to look at class methods, what they do...
3321 could someone post some examples of how to use ri, or any
3322 other tool that would be useful in that regard?
3324 for objective C there was a nice little application
3325 AppKiDo 0.94 which let you look at classes, methods...
3327 In xcode there were ways to use key combinations to find
3328 definitions... What is the best way -- beside the book which
3329 should come next week -- to find out information
3331 -------------------------------------------------------
3333 I have also been thinking about GUI and how to do that in
3334 Ruby for a web application. I found an example using tk
3336 Here is the snipet I found which makes a button:
3338 require 'tk'
3339 root = TkRoot.new
3340 button = TkButton.new(root) {
3341   text "Hello,Anne"
3342   command proc { puts "I said"}
3346 button.pack
3347 Tk.mainloop
3349 It runs on ruby terminal, but it does not run on rubycocoa,
3350 and it does not run on emacs.
3352 I would really like to be set up in an environement where I
3353 don't have to use terminal and unix commands. I would like
3354 to use mac applications, mac windows and editors. I don't
3355 know what to do to get a set up I will be able to use with
3356 GUIs if this basic one does not work!
3358 Any idea why rubycocoa and emacs don't find tcltklib?
3359 It is a directory in ext in the ruby 1.8.3 source file, but
3360 I don't know what happens to it during install or how to
3361 set up a mac path so ruby finds it in those other
3362 environments
3364 ------------------------------------------------------
3366 In addition, I got a response which suggest GUIs are quite
3367 complex and I don't know which package I should use, if it
3368 is set up by default or not...
3370 Here is the response:
3371 > rubycocoa is the Ruby interface bindings to the native
3372 > cocoa GUI toolkit of the Mac.  tcl is a scripting
3373 > language and its standard GUI toolkit is tk that uses
3374 > non native widgets - i.e. has its own unique look and
3375 > feel.  tclTkAqua is the tcl Tk toolkit that uses native
3376 > Mac widgets The tk toolkit is widely ported and many
3377 > other bindings to it have been produced, including Ruby.
3379 > If you are using rubycocoa then it doesn't make sense to
3380 > me why you would want to use tcl, tk or tckTkAqua as you
3381 > are trying to mix different GUI toolkits.
3383 What guis will we be using for this course?
3385 thanks for any help you can give me.
3387 Anne
3389 my two posts on comp.lang.ruby
3391 http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/b68d9da3118402c1
3392 http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/dd608f51c6f47e9e/b00540532449bd8f#b00540532449bd8f
3396 From anne@wjh.harvard.edu  Sun Nov 20 04:18:32 2005
3397 Return-Path: <anne@wjh.harvard.edu>
3398 X-Original-To: courses@linuxchix.org
3399 Delivered-To: courses@linuxchix.org
3400 Received: from localhost (localhost [127.0.0.1])
3401         by www.linuxchix.org (Postfix) with ESMTP id 81665273214
3402         for <courses@linuxchix.org>; Sun, 20 Nov 2005 04:18:32 +1100 (EST)
3403 Received: from www.linuxchix.org ([127.0.0.1])
3404         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3405         id 17173-09 for <courses@linuxchix.org>;
3406         Sun, 20 Nov 2005 04:18:32 +1100 (EST)
3407 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
3408         by www.linuxchix.org (Postfix) with ESMTP id F0D7E27320D
3409         for <courses@linuxchix.org>; Sun, 20 Nov 2005 04:18:16 +1100 (EST)
3410 Received: from localhost (anne@localhost)
3411         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jAJHHqP06464
3412         for <courses@linuxchix.org>; Sat, 19 Nov 2005 12:17:52 -0500 (EST)
3413 Date: Sat, 19 Nov 2005 12:17:52 -0500 (EST)
3414 From: Anne G <anne@wjh.harvard.edu>
3415 To: <courses@linuxchix.org>
3416 Subject: Re: [Courses] [Ruby] Lesson 0: Installing
3417 In-Reply-To: <Pine.SOL.4.30.0511171704380.13651-100000@wjh1.wjh.harvard.edu>
3418 Message-ID: <Pine.SOL.4.30.0511191211530.5907-100000@wjh1.wjh.harvard.edu>
3419 MIME-Version: 1.0
3420 Content-Type: TEXT/PLAIN; charset=US-ASCII
3421 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3422 X-Topics: Introduction to Ruby
3423 X-BeenThere: courses@linuxchix.org
3424 X-Mailman-Version: 2.1.5
3425 Precedence: list
3426 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3427 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3428         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3429 List-Archive: <http://linuxchix.org/pipermail/courses>
3430 List-Post: <mailto:courses@linuxchix.org>
3431 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3432 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3433         <mailto:courses-request@linuxchix.org?subject=subscribe>
3434 X-List-Received-Date: Sat, 19 Nov 2005 17:18:32 -0000
3435 Content-Length: 821
3436 Lines: 23
3438 > I'm not planning to do any GUI programming in this course.
3440 OK, that's fine. I need to figure out how to do Object
3441 oriented programming, and it is probably better not to
3442 get involved with GUIs right now. Because lesson 1 talked
3443 about showing pictures, I assumed we would need an
3444 interface... and started looking in that direction.
3446 ---------------------------------------------------
3448 I did get emacs to work with my button snipet with tk.
3449 it now works. If anyone is interested, here is the
3450 discussion
3451 http://groups.google.com/group/gnu.emacs.help/browse_frm/thread/751afb08ac720d06/0468760d41b3c2a6?lnk=raot#0468760d41b3c2a6
3453 It has to do with conflict between two installations of ruby
3454 on the same computer, (1.6 that comes with panther, and
3455 1.8.3 I installed )  and setting the path.
3457 So now, on to lesson 1!
3459 Anne
3462 From laurel.fan@gmail.com  Tue Nov 15 17:47:18 2005
3463 Return-Path: <laurel.fan@gmail.com>
3464 X-Original-To: courses@linuxchix.org
3465 Delivered-To: courses@linuxchix.org
3466 Received: from localhost (localhost [127.0.0.1])
3467         by www.linuxchix.org (Postfix) with ESMTP id AFD8727320F
3468         for <courses@linuxchix.org>; Tue, 15 Nov 2005 17:47:18 +1100 (EST)
3469 Received: from www.linuxchix.org ([127.0.0.1])
3470         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3471         id 12377-10 for <courses@linuxchix.org>;
3472         Tue, 15 Nov 2005 17:47:18 +1100 (EST)
3473 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.206])
3474         by www.linuxchix.org (Postfix) with ESMTP id CDEA72731B6
3475         for <courses@linuxchix.org>; Tue, 15 Nov 2005 17:47:17 +1100 (EST)
3476 Received: by xproxy.gmail.com with SMTP id s9so773868wxc
3477         for <courses@linuxchix.org>; Mon, 14 Nov 2005 22:47:13 -0800 (PST)
3478 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
3479         h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
3480         b=aqMeiIRsejc3Th+FRs586eePoGG7skJ1pxplOCbZCwaprFOdn0wkVTiVrlZ+IYpxXvP+FH65hoyQWlxUl0ev17wSqOEztdsIp+9YpXCscfIWVrnLAr3jhOHTgR5SjV0owLt9U0kmwnOe7TSb66cctSTGZ/DrVEedpyM9l1PiQv0=
3481 Received: by 10.70.74.20 with SMTP id w20mr114541wxa;
3482         Mon, 14 Nov 2005 22:47:13 -0800 (PST)
3483 Received: by 10.70.94.2 with HTTP; Mon, 14 Nov 2005 22:47:13 -0800 (PST)
3484 Message-ID: <8b1e030f0511142247ta24edc1g6fb9349756e892be@mail.gmail.com>
3485 Date: Mon, 14 Nov 2005 22:47:13 -0800
3486 From: Laurel Fan <laurel.fan@gmail.com>
3487 To: courses@linuxchix.org
3488 Subject: [Courses] [Ruby] Lesson 1: Introduction, Classes, Objects,
3489         and Variables
3490 MIME-Version: 1.0
3491 Content-Type: text/plain; charset=ISO-8859-1
3492 Content-Transfer-Encoding: quoted-printable
3493 Content-Disposition: inline
3494 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3495 X-Topics: Introduction to Ruby
3496 X-BeenThere: courses@linuxchix.org
3497 X-Mailman-Version: 2.1.5
3498 Precedence: list
3499 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3500 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3501         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3502 List-Archive: <http://linuxchix.org/pipermail/courses>
3503 List-Post: <mailto:courses@linuxchix.org>
3504 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3505 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3506         <mailto:courses-request@linuxchix.org?subject=subscribe>
3507 X-List-Received-Date: Tue, 15 Nov 2005 06:47:19 -0000
3508 Content-Length: 3249
3509 Lines: 90
3511 =3D Lesson 1: Introduction, Classes, Objects, and Variables
3513 =3D=3D Reading
3515 If you're using the second edition on paper or pdf, the reading is ....
3517 If you're using the first edition on the web, the reading is the
3518 following sections:
3520 Foreword: http://www.rubycentral.com/book/foreword.html
3521 Preface: http://www.rubycentral.com/book/preface.html
3522 Roadmap: http://www.rubycentral.com/book/roadmap.html
3523 Ruby.new: http://www.rubycentral.com/book/intro.html
3524 Classes, Objects, and Variables:  http://www.rubycentral.com/book/tut_class=
3525 es.ht
3528 (Don't worry, the first three links are introductory material for the
3529 book itself...)
3531 =3D=3D Homework
3533 (As usual, you can of course do as much or as little as you like.  If
3534 you don't have time to answer every single question, you should still
3535 post what you have done)
3537 =3D=3D=3D Questions
3539 1. Any questions about the reading?  Anything that you didn't
3540    understand, or want to know more about?
3542 2. For those who know other programming languages, what are some ways
3543    that Ruby is different from other languages you know?
3545 3. What's the difference between an instance variable and class
3546    variable?
3548 4. What's the difference between a variable and an attribute?
3550 =3D=3D=3D Problems
3552 1. Defining classes: photo gallery.  Think about what classes you
3553    would need to define to write a web photo gallery application.  For
3554    now, don't think of the actual implementation details of handling
3555    web requests, displaying images, etc.  Obviously you'll need to
3556    represent a photo.  What attributes does it have?  What other
3557    objects do you need?
3558 post what you have done)
3560 =3D=3D=3D Questions
3562 1. Any questions about the reading?  Anything that you didn't
3563    understand, or want to know more about?
3565 2. For those who know other programming languages, what are some ways
3566    that Ruby is different from other languages you know?
3568 3. What's the difference between an instance variable and class
3569    variable?
3571 4. What's the difference between a variable and an attribute?
3573 =3D=3D=3D Problems
3575 1. Defining classes: photo gallery.  Think about what classes you
3576    would need to define to write a web photo gallery application.  For
3577    now, don't think of the actual implementation details of handling
3578    web requests, displaying images, etc.  Obviously you'll need to
3579    represent a photo.  What attributes does it have?  What other
3580    objects do you need?
3582 2. Defining classes: /proc. (This might not be as interesting for
3583    windows users).  On unix, the /proc filesystem is a virtual
3584    filesystem containing information about the running processes
3585    (among other things).  It contains a directory for each running
3586    process, which contains information about the process, such as the
3587    command line, the amount of memory it's using, etc).  Define a set
3588    of classes to represent the process data in /proc.
3590 Bonus: Actually write a program to look at the data in proc and do
3591 something with it.  A good start would be to print out the pids and
3592 command lines.  You might want to look up the File and Dir classes.
3594 Thats it, Lesson 2 (covering chapters 4-6: Containers, Blocks, and
3595 Iterators; Standard Types; More About Methods) will be posted Nov 28
3596 (in 2 weeks).
3599 Laurel Fan
3600 http://dreadnought.gorgorg.org
3602 From akkana@shallowsky.com  Sun Nov 27 17:04:13 2005
3603 Return-Path: <akkana@shallowsky.com>
3604 X-Original-To: courses@linuxchix.org
3605 Delivered-To: courses@linuxchix.org
3606 Received: from localhost (localhost [127.0.0.1])
3607         by www.linuxchix.org (Postfix) with ESMTP id 41DE527321A
3608         for <courses@linuxchix.org>; Sun, 27 Nov 2005 17:04:13 +1100 (EST)
3609 Received: from www.linuxchix.org ([127.0.0.1])
3610         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3611         id 11982-09 for <courses@linuxchix.org>;
3612         Sun, 27 Nov 2005 17:04:13 +1100 (EST)
3613 Received: from moon.timocharis.com (adsl-69-105-235-1.dsl.pltn13.pacbell.net
3614         [69.105.235.1])
3615         by www.linuxchix.org (Postfix) with ESMTP id 81EE3273216
3616         for <courses@linuxchix.org>; Sun, 27 Nov 2005 17:04:12 +1100 (EST)
3617 Received: by moon.timocharis.com (Postfix, from userid 666)
3618         id 697462087; Sat, 26 Nov 2005 22:04:07 -0800 (PST)
3619 Date: Sat, 26 Nov 2005 22:04:07 -0800
3620 From: Akkana Peck <akkana@shallowsky.com>
3621 To: courses@linuxchix.org
3622 Subject: Re: [Courses] [Ruby] Lesson 1: Introduction, Classes, Objects,
3623         and Variables
3624 Message-ID: <20051127060407.GA13512@shallowsky.com>
3625 Mail-Followup-To: courses@linuxchix.org
3626 References: <8b1e030f0511142247ta24edc1g6fb9349756e892be@mail.gmail.com>
3627 Mime-Version: 1.0
3628 Content-Type: text/plain; charset=us-ascii
3629 Content-Disposition: inline
3630 In-Reply-To: <8b1e030f0511142247ta24edc1g6fb9349756e892be@mail.gmail.com>
3631 User-Agent: Mutt/1.5.9i
3632 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3633 X-Topics: Introduction to Ruby
3634 X-BeenThere: courses@linuxchix.org
3635 X-Mailman-Version: 2.1.5
3636 Precedence: list
3637 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3638 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3639         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3640 List-Archive: <http://linuxchix.org/pipermail/courses>
3641 List-Post: <mailto:courses@linuxchix.org>
3642 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3643 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3644         <mailto:courses-request@linuxchix.org?subject=subscribe>
3645 X-List-Received-Date: Sun, 27 Nov 2005 06:04:13 -0000
3646 Content-Length: 4470
3647 Lines: 95
3649 Laurel Fan writes:
3650 > 2. For those who know other programming languages, what are some ways
3651 >    that Ruby is different from other languages you know?
3653 The biggest difference is that everything is a class -- even
3654 numbers. Being able to say something like -1942.abs instead of
3655 abs(-1942) or Math.abs(-1942) is neat. I like it. One of the
3656 confusing things about Python (though I do like Python a lot)
3657 is figuring out, especially with strings, when I need to say
3658 s.replace("foo", "bar") vs. string.replace(s, 'foo', 'bar');
3659 or sometimes needing to say something like Integer(-1942).abs
3660 (i.e. some things are already an object, but other things you
3661 have to convert into an object). Ruby is more consistent.
3663 The expression interpolation is cool, too: being able to say
3664 puts "Good night, #{name}", where name is the name of one of
3665 the function arguments, is very useful.
3667 One thing I don't like as much is the if ... elsif ... end
3668 structure. To be honest. I like C-style braces best, though
3669 Python's colon-plus-indentation works well too. "end" isn't
3670 so bad, but as someone who uses lots of different languages,
3671 it drives me batty to try to remember which languages use
3672 "else if", which "elif", which "elsif", etc. ... and I wish
3673 people would just stop designing languages that way.
3675 Blocks and "yield" seem like an unnecessary complexity, but
3676 perhaps eventually I'll see the point. (The examples in the
3677 book don't really justify why this is needed.)
3679 > 3. What's the difference between an instance variable and class
3680 >    variable?
3682 An instance variable belongs to a specific object (an instance
3683 of some class). Each instance has its own copy of each instance
3684 variable. A class variable is shared by the whole class; the whole
3685 class only has one copy, and each instance of the class can see
3686 the value of that class variable.
3688 > 4. What's the difference between a variable and an attribute?
3690 Attributes look like instance variables to code outside the class,
3691 but they're actually implemented as functions (sometimes? Always?)
3692 If you use attr_reader (or do the same thing by hand), then the
3693 function that implements the attribute that's visible outside
3694 the class will probably just return the value of the instance
3695 variable of the same name.
3697 > 1. Defining classes: photo gallery.  Think about what classes you
3698 >    would need to define to write a web photo gallery application.  For
3699 >    now, don't think of the actual implementation details of handling
3700 >    web requests, displaying images, etc.  Obviously you'll need to
3701 >    represent a photo.  What attributes does it have?  What other
3702 >    objects do you need?
3704 Okay, just a quick start on this.
3705 (Note: I have my own simple web photo gallery code, a really basic
3706 setup, that I wrote in perl a long time ago and later translated
3707 into PHP. So I've thought about this a little, though my
3708 implementation is just a bare-bones one and doesn't do most
3709 of what I'll suggest here.)
3711 The only thing the photo object absolutely needs to have is the
3712 filename (the thing that's going to go into the IMG tag in the page).
3714 But there are some other things it really ought to have:
3716 * Something to put in the ALT attribute of the IMG tag on the page
3717   (a few words of description).
3718 * A longer description (may be blank) describing what the photo is.
3719 * Width and Height of the image.
3720 * EXIF information, if any (date/time, size, what camera was used,
3721   exposure data like aperture and shutter speed)
3722 * Other sizes which might be available (thumbnail? fullres?)
3723 * Maybe information on copyright or how to order a print,
3724   depending on the intended user of the gallery.
3726 Other objects:
3727 * gallery: information about this particular gallery, mainly a
3728   title indicating what the pictures are, like "Vacation in Hawaii",
3729   maybe a date, maybe some descriptive text, maybe cross-references
3730   to other similar galleries like "Vacation in Tahiti".
3731 * Some way to store links back to the top level, and possibly
3732   to other galleries. That might belong in the gallery object too,
3733   but there might be other navigation information needed which
3734   might justify some other object.
3735 * Something that can handle layout: things like how many images can
3736   we display per row, and where are we in the row?
3738 I haven't done anything on the /proc suggestion -- though it does
3739 sound like a fun exercise. But I ran out of time and decided it
3740 was better to post what I had than keep it sitting any longer
3741 waiting until I had time to fiddle with /proc.
3743         ...Akkana
3745 From laurel.fan@gmail.com  Fri Nov 18 09:43:52 2005
3746 Return-Path: <laurel.fan@gmail.com>
3747 X-Original-To: courses@linuxchix.org
3748 Delivered-To: courses@linuxchix.org
3749 Received: from localhost (localhost [127.0.0.1])
3750         by www.linuxchix.org (Postfix) with ESMTP id 389B0273212
3751         for <courses@linuxchix.org>; Fri, 18 Nov 2005 09:43:52 +1100 (EST)
3752 Received: from www.linuxchix.org ([127.0.0.1])
3753         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3754         id 02329-08 for <courses@linuxchix.org>;
3755         Fri, 18 Nov 2005 09:43:52 +1100 (EST)
3756 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.207])
3757         by www.linuxchix.org (Postfix) with ESMTP id 6CFAD27320D
3758         for <courses@linuxchix.org>; Fri, 18 Nov 2005 09:43:51 +1100 (EST)
3759 Received: by xproxy.gmail.com with SMTP id s9so45306wxc
3760         for <courses@linuxchix.org>; Thu, 17 Nov 2005 14:43:44 -0800 (PST)
3761 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
3762         h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
3763         b=ODtwkkk671zgKxQ0NbAO5GHvpWZFdhFEI4zCljZIKyqFpRC0Fe2fnunKQn8eXvz4VzJQkl5lV9BgVAQxYz6YtM9gC1WSQskNPJ6iY1t6P4//bcC1uX+pwTD0NTnuaP4I1b0aADpG/dccUYZ+A52A5nSI4iLe1TQTce+2QoQpTlU=
3764 Received: by 10.70.60.9 with SMTP id i9mr5715492wxa;
3765         Thu, 17 Nov 2005 14:43:44 -0800 (PST)
3766 Received: by 10.70.94.2 with HTTP; Thu, 17 Nov 2005 14:43:44 -0800 (PST)
3767 Message-ID: <8b1e030f0511171443u15c6b989p62dc38968b4119be@mail.gmail.com>
3768 Date: Thu, 17 Nov 2005 14:43:44 -0800
3769 From: Laurel Fan <laurel.fan@gmail.com>
3770 To: courses@linuxchix.org
3771 Subject: [Courses] [Ruby] GUIs (Was: Lesson 0: Installing)
3772 MIME-Version: 1.0
3773 Content-Type: text/plain; charset=ISO-8859-1
3774 Content-Transfer-Encoding: quoted-printable
3775 Content-Disposition: inline
3776 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3777 X-Topics: Introduction to Ruby
3778 X-BeenThere: courses@linuxchix.org
3779 X-Mailman-Version: 2.1.5
3780 Precedence: list
3781 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3782 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3783         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3784 List-Archive: <http://linuxchix.org/pipermail/courses>
3785 List-Post: <mailto:courses@linuxchix.org>
3786 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3787 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3788         <mailto:courses-request@linuxchix.org?subject=subscribe>
3789 X-List-Received-Date: Thu, 17 Nov 2005 22:43:52 -0000
3790 Content-Length: 754
3791 Lines: 18
3793 On 11/17/05, Anne G <anne@wjh.harvard.edu> wrote:
3794 > What guis will we be using for this course?
3796 Are you looking for a GUI application for you to use to write ruby
3797 code?  Or are you talking about creating grapical programs with ruby?=20
3798 I don't have any experience with either, and I'm not planning to do
3799 any GUI programming in this course.
3801 However, there is nothing to stop you from using any graphical editor
3802 or IDE that you wish to write your code (I can't help you with
3803 specifics because I haven't used any.. I use emacs with ruby-mode).=20
3804 If you're not interested in doing anything at all with the terminal,
3805 this may not be the course for you, unless someone else here can help
3806 you figure that out...
3809 Laurel Fan
3810 http://dreadnought.gorgorg.org
3812 From anne@wjh.harvard.edu  Thu Nov 24 05:41:27 2005
3813 Return-Path: <anne@wjh.harvard.edu>
3814 X-Original-To: courses@linuxchix.org
3815 Delivered-To: courses@linuxchix.org
3816 Received: from localhost (localhost [127.0.0.1])
3817         by www.linuxchix.org (Postfix) with ESMTP id ADE88273218
3818         for <courses@linuxchix.org>; Thu, 24 Nov 2005 05:41:26 +1100 (EST)
3819 Received: from www.linuxchix.org ([127.0.0.1])
3820         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3821         id 16568-02 for <courses@linuxchix.org>;
3822         Thu, 24 Nov 2005 05:41:26 +1100 (EST)
3823 Received: from wjh2.wjh.harvard.edu (wjh2.wjh.harvard.edu [140.247.94.249])
3824         by www.linuxchix.org (Postfix) with ESMTP id AACA8273203
3825         for <courses@linuxchix.org>; Thu, 24 Nov 2005 05:41:25 +1100 (EST)
3826 Received: from localhost (anne@localhost)
3827         by wjh2.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jANIfHQ25948
3828         for <courses@linuxchix.org>; Wed, 23 Nov 2005 13:41:18 -0500 (EST)
3829 Date: Wed, 23 Nov 2005 13:41:17 -0500 (EST)
3830 From: Anne G <anne@wjh.harvard.edu>
3831 To: <courses@linuxchix.org>
3832 Subject: [Courses] [Ruby] Lesson 1: Classes 
3833 Message-ID: <Pine.SOL.4.30.0511231341020.25297-100000@wjh2.wjh.harvard.edu>
3834 MIME-Version: 1.0
3835 Content-Type: TEXT/PLAIN; charset=US-ASCII
3836 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3837 X-Topics: Introduction to Ruby
3838 X-BeenThere: courses@linuxchix.org
3839 X-Mailman-Version: 2.1.5
3840 Precedence: list
3841 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3842 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3843         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3844 List-Archive: <http://linuxchix.org/pipermail/courses>
3845 List-Post: <mailto:courses@linuxchix.org>
3846 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3847 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3848         <mailto:courses-request@linuxchix.org?subject=subscribe>
3849 X-List-Received-Date: Wed, 23 Nov 2005 18:41:28 -0000
3850 Content-Length: 871
3851 Lines: 28
3854 Happy Thanksgiving, for those who celebrate it.
3856 I have a project I am working on, parsing subject data that
3857 has been concatennated into one giant file. I figure I can
3858 write a class and small methods as an exercise...
3860 but it is just as easy to process the file line by line with
3861 a few switches here and there, without specifying any new
3862 class (other than an array instance etc)..
3864 The song example in the book is a database.  What are other
3865 examples of common objects? When is it worth creating an
3866 object, versus plain code?
3868 I understand the theory about encapsulation, but in practice
3869 my code is fairly short, and I only use functions to
3870 identify what different sections of the code do. I use
3871 globals to avoid the hastle of passing info to the fxs.
3873 so I don't really know, how do you figure out what part
3874 of the code would be a good candidate for a class.
3876 Anne
3882 From anne@wjh.harvard.edu  Sun Nov 27 01:19:58 2005
3883 Return-Path: <anne@wjh.harvard.edu>
3884 X-Original-To: courses@linuxchix.org
3885 Delivered-To: courses@linuxchix.org
3886 Received: from localhost (localhost [127.0.0.1])
3887         by www.linuxchix.org (Postfix) with ESMTP id C418527321A
3888         for <courses@linuxchix.org>; Sun, 27 Nov 2005 01:19:58 +1100 (EST)
3889 Received: from www.linuxchix.org ([127.0.0.1])
3890         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3891         id 07055-02 for <courses@linuxchix.org>;
3892         Sun, 27 Nov 2005 01:19:58 +1100 (EST)
3893 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
3894         by www.linuxchix.org (Postfix) with ESMTP id BB29A273211
3895         for <courses@linuxchix.org>; Sun, 27 Nov 2005 01:19:57 +1100 (EST)
3896 Received: from localhost (anne@localhost)
3897         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jAQEJlK01731
3898         for <courses@linuxchix.org>; Sat, 26 Nov 2005 09:19:47 -0500 (EST)
3899 Date: Sat, 26 Nov 2005 09:19:47 -0500 (EST)
3900 From: Anne G <anne@wjh.harvard.edu>
3901 To: <courses@linuxchix.org>
3902 Subject: Re: [Courses] [Ruby] Lesson 1: Classes 
3903 In-Reply-To: <Pine.SOL.4.30.0511231341020.25297-100000@wjh2.wjh.harvard.edu>
3904 Message-ID: <Pine.SOL.4.30.0511260915340.1502-100000@wjh1.wjh.harvard.edu>
3905 MIME-Version: 1.0
3906 Content-Type: TEXT/PLAIN; charset=US-ASCII
3907 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3908 X-Topics: Introduction to Ruby
3909 X-BeenThere: courses@linuxchix.org
3910 X-Mailman-Version: 2.1.5
3911 Precedence: list
3912 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3913 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3914         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3915 List-Archive: <http://linuxchix.org/pipermail/courses>
3916 List-Post: <mailto:courses@linuxchix.org>
3917 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3918 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3919         <mailto:courses-request@linuxchix.org?subject=subscribe>
3920 X-List-Received-Date: Sat, 26 Nov 2005 14:19:59 -0000
3921 Content-Length: 627
3922 Lines: 22
3925 > You can spend a bit of time at the beginning of a course
3926 > having students use programs which emphasize the
3927 > interactions between objects. Students need to have
3928 > clear ideas about objects, messages, behavior, and
3929 > state.
3931 I can't find any information about how to have objects
3932 interact.
3934 Most of the examples are about sending a method to an object
3935 from the program. I can't find an example of an object
3936 sending a message to an other object.
3938 How do you get an object to send a message to an other
3939 object given that the objects don't yet exist when the
3940 classes and instance method are defined in the code?
3942 thanks
3944 Anne
3947 From laurel.fan@gmail.com  Sun Nov 27 07:14:20 2005
3948 Return-Path: <laurel.fan@gmail.com>
3949 X-Original-To: courses@linuxchix.org
3950 Delivered-To: courses@linuxchix.org
3951 Received: from localhost (localhost [127.0.0.1])
3952         by www.linuxchix.org (Postfix) with ESMTP id E364C27321B
3953         for <courses@linuxchix.org>; Sun, 27 Nov 2005 07:14:19 +1100 (EST)
3954 Received: from www.linuxchix.org ([127.0.0.1])
3955         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
3956         id 08874-03 for <courses@linuxchix.org>;
3957         Sun, 27 Nov 2005 07:14:19 +1100 (EST)
3958 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.207])
3959         by www.linuxchix.org (Postfix) with ESMTP id D88DA273218
3960         for <courses@linuxchix.org>; Sun, 27 Nov 2005 07:14:18 +1100 (EST)
3961 Received: by xproxy.gmail.com with SMTP id s9so1832022wxc
3962         for <courses@linuxchix.org>; Sat, 26 Nov 2005 12:14:15 -0800 (PST)
3963 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
3964         h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
3965         b=TFvm4HURvdnzuF++R65zQr6RSQHa1hLT8uuDzHb1oxiGSEILia0yNLur6zpYGtVklXwY11YfiuMAbp6VzbLUHLzc2vyGC3LBT+9O1WFrBWh1YxjZsucFTZrfD9WR6gjtHcSPOrcjaEUb7b8Lw9gyIcoAJ3pcu5ao1OH//8sKUfo=
3966 Received: by 10.70.100.17 with SMTP id x17mr8096792wxb;
3967         Sat, 26 Nov 2005 12:07:51 -0800 (PST)
3968 Received: by 10.70.92.7 with HTTP; Sat, 26 Nov 2005 12:07:51 -0800 (PST)
3969 Message-ID: <8b1e030f0511261207t53494f0aqa2b68319861cd8ef@mail.gmail.com>
3970 Date: Sat, 26 Nov 2005 12:07:51 -0800
3971 From: Laurel Fan <laurel.fan@gmail.com>
3972 To: Anne G <anne@wjh.harvard.edu>
3973 Subject: Re: [Courses] [Ruby] Lesson 1: Classes
3974 In-Reply-To: <Pine.SOL.4.30.0511260915340.1502-100000@wjh1.wjh.harvard.edu>
3975 MIME-Version: 1.0
3976 Content-Type: text/plain; charset=ISO-8859-1
3977 Content-Transfer-Encoding: quoted-printable
3978 Content-Disposition: inline
3979 References: <Pine.SOL.4.30.0511231341020.25297-100000@wjh2.wjh.harvard.edu>
3980         <Pine.SOL.4.30.0511260915340.1502-100000@wjh1.wjh.harvard.edu>
3981 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
3982 X-Topics: Introduction to Ruby
3983 Cc: courses@linuxchix.org
3984 X-BeenThere: courses@linuxchix.org
3985 X-Mailman-Version: 2.1.5
3986 Precedence: list
3987 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
3988 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3989         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
3990 List-Archive: <http://linuxchix.org/pipermail/courses>
3991 List-Post: <mailto:courses@linuxchix.org>
3992 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
3993 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
3994         <mailto:courses-request@linuxchix.org?subject=subscribe>
3995 X-List-Received-Date: Sat, 26 Nov 2005 20:14:20 -0000
3996 Content-Length: 2188
3997 Lines: 65
3999 On 11/26/05, Anne G <anne@wjh.harvard.edu> wrote:
4000 > I can't find any information about how to have objects
4001 > interact.
4003 > Most of the examples are about sending a method to an object
4004 > from the program. I can't find an example of an object
4005 > sending a message to an other object.
4007 > How do you get an object to send a message to an other
4008 > object given that the objects don't yet exist when the
4009 > classes and instance method are defined in the code?
4011 I'm not quite clear on what you're asking, but I think you might be
4012 over thinking it a little.  The other objects don't need to exist when
4013 you are defining the methods, only when the method is actually called.
4014  Methods can call methods on other objects pretty much whenever they
4015 feel like.  Let's say I'm writing a program to control my smart
4016 fridge.
4019 class Fridge
4020   def init
4021     @milk_cartons =3D Array.new()
4022   end
4024   def add_milk_carton(carton)
4025     @milk_cartons.add
4026   end
4028   def has_milk?
4029     @milk_cartons.each do |carton|
4030       if !carton.empty?
4031         return true
4032       end
4033     end
4034     false
4035   end
4038 In this case, the has_milk? function sends a message to the object
4039 that we're using to represent milk cartons.  We haven't defined that
4040 object yet, but as long as it's defined by the time we run the program
4041 and call the function, it'll work fine.
4043 This is something that's mostly unique to ruby:  Most of the time, it
4044 doesn't matter what the actual type/class of an object is.  It only
4045 matters what methods it responds to.  For example, in this case, we
4046 could define a new MilkCarton class that implements the empty? method,
4047 but if we're feeling lazy we could use a String (since String
4048 implements empty? as well).
4050 There's even a special method called method_missing that is called on
4051 an object when we try to send it a message (ie. call a method) that it
4052 doesn't understand.  This lets you implement methods without actually
4053 implementing them.  The book has a toy example of what you can do with
4054 this:
4056 http://www.rubycentral.com/book/ref_c_object.html#Object.method_missing
4058 Thanks for all of your questions (let me know if this wasn't clear or
4059 didn't answer your question)!
4062 Laurel Fan
4063 http://dreadnought.gorgorg.org
4065 From anne@wjh.harvard.edu  Sun Nov 27 07:53:07 2005
4066 Return-Path: <anne@wjh.harvard.edu>
4067 X-Original-To: courses@linuxchix.org
4068 Delivered-To: courses@linuxchix.org
4069 Received: from localhost (localhost [127.0.0.1])
4070         by www.linuxchix.org (Postfix) with ESMTP id 88C7127320D
4071         for <courses@linuxchix.org>; Sun, 27 Nov 2005 07:53:07 +1100 (EST)
4072 Received: from www.linuxchix.org ([127.0.0.1])
4073         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
4074         id 09010-07 for <courses@linuxchix.org>;
4075         Sun, 27 Nov 2005 07:53:07 +1100 (EST)
4076 Received: from wjh2.wjh.harvard.edu (wjh2.wjh.harvard.edu [140.247.94.249])
4077         by www.linuxchix.org (Postfix) with ESMTP id 8782A2731C5
4078         for <courses@linuxchix.org>; Sun, 27 Nov 2005 07:53:06 +1100 (EST)
4079 Received: from localhost (anne@localhost)
4080         by wjh2.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jAQKr3d27505
4081         for <courses@linuxchix.org>; Sat, 26 Nov 2005 15:53:03 -0500 (EST)
4082 Date: Sat, 26 Nov 2005 15:53:02 -0500 (EST)
4083 From: Anne G <anne@wjh.harvard.edu>
4084 To: <courses@linuxchix.org>
4085 Subject: Re: [Courses] [Ruby] Lesson 1: Classes
4086 In-Reply-To: <8b1e030f0511261207t53494f0aqa2b68319861cd8ef@mail.gmail.com>
4087 Message-ID: <Pine.SOL.4.30.0511261532430.25494-100000@wjh2.wjh.harvard.edu>
4088 MIME-Version: 1.0
4089 Content-Type: TEXT/PLAIN; charset=US-ASCII
4090 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
4091 X-Topics: Introduction to Ruby
4092 X-BeenThere: courses@linuxchix.org
4093 X-Mailman-Version: 2.1.5
4094 Precedence: list
4095 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
4096 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4097         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
4098 List-Archive: <http://linuxchix.org/pipermail/courses>
4099 List-Post: <mailto:courses@linuxchix.org>
4100 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
4101 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4102         <mailto:courses-request@linuxchix.org?subject=subscribe>
4103 X-List-Received-Date: Sat, 26 Nov 2005 20:53:07 -0000
4104 Content-Length: 1293
4105 Lines: 58
4107 Here is the example I am thinking about:
4109 I define a class with two class variables and a storage
4110 array, and I create two instances
4111 datainst=dataClass.new
4112 infoinst=dataClass.new
4114 the objects datainst and infoinst both have access to @@Arr
4115 and @@ind, and each have their own array.
4117 class dataClass
4118      def initialize
4119         @@Arr=array read from file, constant
4120         @@ind=0
4121         @storeAr=[]
4122      end
4125 I can get my program rolling by calling a method, say
4126 datainst.lookforX
4128 class dataClass
4129     def lookforX
4130         look for X in @@arr[@@ind]
4131         if X not found
4132             increase @@ind
4133             Self.lookforX
4134         else X is found
4135             Send a message to the other object to tell it
4136 its its turn to do something   ?????  HOW DO I DO THAT?
4137             break out of all recursions
4138         end
4139     end
4142 The object datainst can call itself with Self but how does
4143 object 'datainst' tell object 'infoinst' that it is its turn
4144 to be processing the array?
4146 In Sams learning ruby, it says that you can define a method
4147 for an object.
4148 def datainst.lookforX
4149      ...
4150      else X is found
4151          infoinst.getinfo
4152          break out of all recursions
4153      end
4154    end
4156 def infoinst.getinfo
4160 Is this the way to go to get two objects to talk to each
4161 other?
4163 anne
4166 From laurel.fan@gmail.com  Tue Nov 29 05:04:16 2005
4167 Return-Path: <laurel.fan@gmail.com>
4168 X-Original-To: courses@linuxchix.org
4169 Delivered-To: courses@linuxchix.org
4170 Received: from localhost (localhost [127.0.0.1])
4171         by www.linuxchix.org (Postfix) with ESMTP id 6038E27321D
4172         for <courses@linuxchix.org>; Tue, 29 Nov 2005 05:04:16 +1100 (EST)
4173 Received: from www.linuxchix.org ([127.0.0.1])
4174         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
4175         id 24271-03 for <courses@linuxchix.org>;
4176         Tue, 29 Nov 2005 05:04:16 +1100 (EST)
4177 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.204])
4178         by www.linuxchix.org (Postfix) with ESMTP id 950F927321A
4179         for <courses@linuxchix.org>; Tue, 29 Nov 2005 05:04:15 +1100 (EST)
4180 Received: by xproxy.gmail.com with SMTP id s9so2151285wxc
4181         for <courses@linuxchix.org>; Mon, 28 Nov 2005 10:04:12 -0800 (PST)
4182 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
4183         h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
4184         b=PWqTRfX6HOef/qf4/1qNmbdRfM3LjnZWFav4hPslIu/vgLDaLqfVRdGzTxAk/HcTVWupEoiL5Ol7UYACTZrVmoQ9qFhvQiRwQFfwIsHQby8NZdgkw8F08ReIMpTrJNWn2RGlBrePK+dOf+XrYUdnORwvyfq5Ld30Q7zxDrCsXbw=
4185 Received: by 10.70.108.8 with SMTP id g8mr882387wxc;
4186         Mon, 28 Nov 2005 10:04:12 -0800 (PST)
4187 Received: by 10.70.92.7 with HTTP; Mon, 28 Nov 2005 10:04:11 -0800 (PST)
4188 Message-ID: <8b1e030f0511281004s1af11bf8tf3f88c684a854475@mail.gmail.com>
4189 Date: Mon, 28 Nov 2005 10:04:11 -0800
4190 From: Laurel Fan <laurel.fan@gmail.com>
4191 To: Anne G <anne@wjh.harvard.edu>
4192 Subject: Re: [Courses] [Ruby] Lesson 1: Classes
4193 In-Reply-To: <Pine.SOL.4.30.0511261532430.25494-100000@wjh2.wjh.harvard.edu>
4194 MIME-Version: 1.0
4195 Content-Type: text/plain; charset=ISO-8859-1
4196 Content-Transfer-Encoding: quoted-printable
4197 Content-Disposition: inline
4198 References: <8b1e030f0511261207t53494f0aqa2b68319861cd8ef@mail.gmail.com>
4199         <Pine.SOL.4.30.0511261532430.25494-100000@wjh2.wjh.harvard.edu>
4200 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
4201 X-Topics: Introduction to Ruby
4202 Cc: courses@linuxchix.org
4203 X-BeenThere: courses@linuxchix.org
4204 X-Mailman-Version: 2.1.5
4205 Precedence: list
4206 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
4207 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4208         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
4209 List-Archive: <http://linuxchix.org/pipermail/courses>
4210 List-Post: <mailto:courses@linuxchix.org>
4211 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
4212 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4213         <mailto:courses-request@linuxchix.org?subject=subscribe>
4214 X-List-Received-Date: Mon, 28 Nov 2005 18:04:16 -0000
4215 Content-Length: 3031
4216 Lines: 104
4218 Comments inline (I hope you don't mind the lack of snipping, I wanted
4219 to preserve the whole context).
4221 On 11/26/05, Anne G <anne@wjh.harvard.edu> wrote:
4222 > Here is the example I am thinking about:
4224 > I define a class with two class variables and a storage
4225 > array, and I create two instances
4226 > datainst=3DdataClass.new
4227 > infoinst=3DdataClass.new
4229 > the objects datainst and infoinst both have access to @@Arr
4230 > and @@ind, and each have their own array.
4232 > class dataClass
4233 >      def initialize
4234 >         @@Arr=3Darray read from file, constant
4235 >         @@ind=3D0
4236 >         @storeAr=3D[]
4237 >      end
4238 > end
4240 > I can get my program rolling by calling a method, say
4241 > datainst.lookforX
4243 > class dataClass
4244 >     def lookforX
4245 >         look for X in @@arr[@@ind]
4246 >         if X not found
4247 >             increase @@ind
4248 >             Self.lookforX
4249 >         else X is found
4250 >             Send a message to the other object to tell it
4251 > its its turn to do something   ?????  HOW DO I DO THAT?
4252 >             break out of all recursions
4253 >         end
4254 >     end
4255 > end
4257 > The object datainst can call itself with Self but how does
4258 > object 'datainst' tell object 'infoinst' that it is its turn
4259 > to be processing the array?
4261 It needs a reference to infoinst.  If you defined the lookForX
4262 function to take another object as an argument, you could pass it
4263 infoinst.  For example:
4265 class dataClass
4266      def lookforX(other) ## this tells us that lookforX takes 'other'
4267 as an argument
4268          look for X in @@arr[@@ind]
4269          if X not found
4270              increase @@ind
4271              Self.lookforX
4272          else X is found
4273              other.doSomethingElse ## this calls lookforX on other.=20
4274 We pass it nil because lookforX takes an argument
4275              Send a message to the other object to tell it
4276  its its turn to do something   ?????  HOW DO I DO THAT?
4277              break out of all recursions
4278          end
4279      end
4281     def doSomethingElse
4282     ...   ## infoinst is the same class as datainst, so we could
4283 define the doSomethingElse method here
4284    end
4285  end
4287 Then, when you call the lookforX method, you would do something like:
4289 datainst.lookforX(infoinst)
4291 This calls lookforX on datainst, and passes it a reference to
4292 infoinst.  So, if you look at the new lookforX definition, it calls
4293 "other.doSomethingElse".  Since other is infoinst, this calls
4294 infoinst.doSomethingElse.
4296 > In Sams learning ruby, it says that you can define a method
4297 > for an object.
4298 > def datainst.lookforX
4299 >      ...
4300 >      else X is found
4301 >          infoinst.getinfo
4302 >          break out of all recursions
4303 >      end
4304 >    end
4305 > end
4306 > def infoinst.getinfo
4307 > ...
4308 > end
4310 > Is this the way to go to get two objects to talk to each
4311 > other?
4313 Not necessarily.  Defining methods for objects (instead of for
4314 classes) can sometimes be useful, but usually if we want objects to
4315 have different methods we make them different classes.  Passing
4316 references to other objects is the usual way of having objects talk to
4317 each other.
4320 Laurel Fan
4321 http://dreadnought.gorgorg.org
4323 From laurel.fan@gmail.com  Sun Nov 27 06:55:36 2005
4324 Return-Path: <laurel.fan@gmail.com>
4325 X-Original-To: courses@linuxchix.org
4326 Delivered-To: courses@linuxchix.org
4327 Received: from localhost (localhost [127.0.0.1])
4328         by www.linuxchix.org (Postfix) with ESMTP id 8044127321B
4329         for <courses@linuxchix.org>; Sun, 27 Nov 2005 06:55:36 +1100 (EST)
4330 Received: from www.linuxchix.org ([127.0.0.1])
4331         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
4332         id 08633-06 for <courses@linuxchix.org>;
4333         Sun, 27 Nov 2005 06:55:36 +1100 (EST)
4334 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.192])
4335         by www.linuxchix.org (Postfix) with ESMTP id C00B5273216
4336         for <courses@linuxchix.org>; Sun, 27 Nov 2005 06:55:35 +1100 (EST)
4337 Received: by xproxy.gmail.com with SMTP id s9so1830110wxc
4338         for <courses@linuxchix.org>; Sat, 26 Nov 2005 11:55:32 -0800 (PST)
4339 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
4340         h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
4341         b=qeKPjkbLfFv44CzM1lBN/7GPwNSCFVOkH7czt4ux+gGXWpbDWzIE1cn4JOt8KF8/+3gB1Ax/iI5ob2h8+vCG+zs+7aS9z2iGorVYpngPOZqsKK5WEv5E3rhVMZ5H0M+SkrsvdoEs1XcdHELYhJN/fu8dljHz++6FJRauhKLS04s=
4342 Received: by 10.70.73.20 with SMTP id v20mr8951370wxa;
4343         Sat, 26 Nov 2005 11:55:32 -0800 (PST)
4344 Received: by 10.70.92.7 with HTTP; Sat, 26 Nov 2005 11:55:32 -0800 (PST)
4345 Message-ID: <8b1e030f0511261155i28a0f41ua560a01331693628@mail.gmail.com>
4346 Date: Sat, 26 Nov 2005 11:55:32 -0800
4347 From: Laurel Fan <laurel.fan@gmail.com>
4348 To: Anne G <anne@wjh.harvard.edu>
4349 Subject: Re: [Courses] [Ruby] Lesson 1: Classes
4350 In-Reply-To: <Pine.SOL.4.30.0511231341020.25297-100000@wjh2.wjh.harvard.edu>
4351 MIME-Version: 1.0
4352 Content-Type: text/plain; charset=ISO-8859-1
4353 Content-Transfer-Encoding: quoted-printable
4354 Content-Disposition: inline
4355 References: <Pine.SOL.4.30.0511231341020.25297-100000@wjh2.wjh.harvard.edu>
4356 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
4357 X-Topics: Introduction to Ruby
4358 Cc: courses@linuxchix.org
4359 X-BeenThere: courses@linuxchix.org
4360 X-Mailman-Version: 2.1.5
4361 Precedence: list
4362 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
4363 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4364         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
4365 List-Archive: <http://linuxchix.org/pipermail/courses>
4366 List-Post: <mailto:courses@linuxchix.org>
4367 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
4368 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4369         <mailto:courses-request@linuxchix.org?subject=subscribe>
4370 X-List-Received-Date: Sat, 26 Nov 2005 19:55:36 -0000
4371 Content-Length: 2440
4372 Lines: 54
4374 On 11/23/05, Anne G <anne@wjh.harvard.edu> wrote:
4375 > I have a project I am working on, parsing subject data that
4376 > has been concatennated into one giant file. I figure I can
4377 > write a class and small methods as an exercise...
4379 > but it is just as easy to process the file line by line with
4380 > a few switches here and there, without specifying any new
4381 > class (other than an array instance etc)..
4383 It's true that very simple programs such as this are probably just as
4384 easily done procedurally as with objects.
4386 > The song example in the book is a database.  What are other
4387 > examples of common objects? When is it worth creating an
4388 > object, versus plain code?
4390 One way of thinking of this is whether something is represented as an
4391 object in a real world, or whether it has multiple properties.  A few
4392 examples:
4394 If I was writing a jigsaw puzzle game, I could make each piece an
4395 object, with properties such as the image on the piece, and the shapes
4396 of the sides.  I could also imagine creating methods to determine
4397 whether two pieces fit together, or to attach two pieces.  To get more
4398 fancy, since I realize that a set of pieces that are already put
4399 together share many of the same properties as a single piece, I could
4400 even make them share some methods and functionality with inheritance
4401 and mixins.
4403 If I was writing a http server, an http request has several
4404 properties, such as the URL, query string, user agent (the type of
4405 browser making the request), even things such as the time of the
4406 request.  I'd like to keep these together in the same object.  One of
4407 the advantages of this is that when writing functions that use some of
4408 this information, I can simply pass the whole request object instead
4409 of individual properties.  Or, when it makes sense, I can put the
4410 methods on my HTTPRequest class.
4412 > I understand the theory about encapsulation, but in practice
4413 > my code is fairly short, and I only use functions to
4414 > identify what different sections of the code do. I use
4415 > globals to avoid the hastle of passing info to the fxs.
4417 > so I don't really know, how do you figure out what part
4418 > of the code would be a good candidate for a class.
4420 For small programs especially, it can be hard to tell whether using
4421 classes gives you any advantage.  It's definitely a lot more obvious
4422 for larger programs;  that's one of the things that makes teaching
4423 object oriented programming difficult.
4426 Laurel Fan
4427 http://dreadnought.gorgorg.org
4429 From anne@wjh.harvard.edu  Fri Dec  2 00:29:27 2005
4430 Return-Path: <anne@wjh.harvard.edu>
4431 X-Original-To: courses@linuxchix.org
4432 Delivered-To: courses@linuxchix.org
4433 Received: from localhost (localhost [127.0.0.1])
4434         by www.linuxchix.org (Postfix) with ESMTP id A496427322A
4435         for <courses@linuxchix.org>; Fri,  2 Dec 2005 00:29:27 +1100 (EST)
4436 Received: from www.linuxchix.org ([127.0.0.1])
4437         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
4438         id 22290-06 for <courses@linuxchix.org>;
4439         Fri, 2 Dec 2005 00:29:27 +1100 (EST)
4440 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
4441         by www.linuxchix.org (Postfix) with ESMTP id 7B91E273224
4442         for <courses@linuxchix.org>; Fri,  2 Dec 2005 00:29:26 +1100 (EST)
4443 Received: from localhost (anne@localhost)
4444         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jB1DTHH21874
4445         for <courses@linuxchix.org>; Thu, 1 Dec 2005 08:29:21 -0500 (EST)
4446 Date: Thu, 1 Dec 2005 08:29:17 -0500 (EST)
4447 From: Anne G <anne@wjh.harvard.edu>
4448 To: <courses@linuxchix.org>
4449 Subject: Re: [Courses] [Ruby] Lesson 1: Classes
4450 Message-ID: <Pine.SOL.4.30.0512010807500.20462-100000@wjh1.wjh.harvard.edu>
4451 MIME-Version: 1.0
4452 Content-Type: TEXT/PLAIN; charset=US-ASCII
4453 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
4454 X-Topics: Introduction to Ruby
4455 X-BeenThere: courses@linuxchix.org
4456 X-Mailman-Version: 2.1.5
4457 Precedence: list
4458 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
4459 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4460         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
4461 List-Archive: <http://linuxchix.org/pipermail/courses>
4462 List-Post: <mailto:courses@linuxchix.org>
4463 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
4464 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4465         <mailto:courses-request@linuxchix.org?subject=subscribe>
4466 X-List-Received-Date: Thu, 01 Dec 2005 13:29:28 -0000
4467 Content-Length: 2530
4468 Lines: 91
4470 Thank you so much Laurel for your response. I will review
4471 classes, and do the reading on lesson2 as you suggested.
4473 First of all your suggestion expended my thinking to include
4474 passing of an object. Thank you so much.
4476 datainst.lookforX(infoinst)
4478 I took this idea and tried to generalize it to 3 objects:
4480 object1 -- stores data,  calls on object2 -- stores first
4481 type of info, calls on object3 -- stores 2nd type of info,
4482 calls back on object1.
4484 I found myself doing the following:
4486 storeobject.lookforX(info1object,info2object,storeobject)
4488 this way lookforX knows to call on info1object
4489 info1object knows to call on info2object
4490 info2object knows to call on storeobject
4493 I love this solution because it is totally within the scope
4494 of what I can do. but it is a bit heavy and still smacks of
4495 procedural in that I have to figure out what the whole chain
4496 of objects will be instead of just relation between
4497 pairs of objects.
4499 Is this the way your suggestion would work with 3 objects?
4501 ---------------------------------------------------------
4503 I found this recent discussion
4504 http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/68acf0f7c8a95138/1bbd14c18a57a45b#1bbd14c18a57a45b
4506 Daniel Schierbeck offered a structure which seems simple
4507 enough, and probably similar to yours, but it is a bit
4508 confusing to my beginner's eye. What is hapening?
4510 Here is what he said
4512 Say you have three classes, A, B, and C, and you want their
4513 instances to be able to communicate. These three classes
4514 will all be instantiated together, so we know that the other
4515 objects are there. You then write a class, let's just call
4516 it Base, that you instantiate instead of the three classes.
4517 It will instantiate them instead, and pass a reference to
4518 itself to each of them.
4520    class Base
4521      attr_reader :a, :b, :c
4523      def initialize
4524        @a, @b, @c = A.new(self), B.new(self), C.new(self)
4525      end
4527      # We'll keep the other classes in here, so we don't
4528      # pollute the main namespace
4529      class A
4530        def initialize(base)
4531          @base = base
4532          @b, @c = base.b, base.c
4533        end
4534      end
4536      class B
4537        def initialize(base)
4538          @base = base
4539          @a, @c = base.a, base.c
4540        end
4541      end
4543      class C
4544        def initialize(base)
4545          @base = base
4546          @a, @b = base.a, base.b
4547        end
4548      end
4549    end
4551 How would I use this in my expended task:
4552 objectA needing to call on objectB needing to call on
4553 objectC needing to call back on objectA
4555 Thank you so much for running this course.
4557 anne
4562 From laurel.fan@gmail.com  Sat Dec  3 05:01:00 2005
4563 Return-Path: <laurel.fan@gmail.com>
4564 X-Original-To: courses@linuxchix.org
4565 Delivered-To: courses@linuxchix.org
4566 Received: from localhost (localhost [127.0.0.1])
4567         by www.linuxchix.org (Postfix) with ESMTP id 48B2427323C
4568         for <courses@linuxchix.org>; Sat,  3 Dec 2005 05:01:00 +1100 (EST)
4569 Received: from www.linuxchix.org ([127.0.0.1])
4570         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
4571         id 02412-02 for <courses@linuxchix.org>;
4572         Sat, 3 Dec 2005 05:01:00 +1100 (EST)
4573 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.205])
4574         by www.linuxchix.org (Postfix) with ESMTP id 6D2D4273230
4575         for <courses@linuxchix.org>; Sat,  3 Dec 2005 05:00:59 +1100 (EST)
4576 Received: by xproxy.gmail.com with SMTP id s9so177462wxc
4577         for <courses@linuxchix.org>; Fri, 02 Dec 2005 10:00:56 -0800 (PST)
4578 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
4579         h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
4580         b=pEAH+QitDWB1gy4v0vs2bfIjFl8twxJAy2NGEsMXvPPK3n9HzfLcaEuNyDHLyzXwMRMfdjEiQ1JJLYc556gdvIlzG3hp/Us9lH8fGtUCkzoyJfRmURz0ky52wABdLqg9cgDvsP0DGnjXL/dnSsnPK32D71kzZflyJEErFcLOFj8=
4581 Received: by 10.70.111.11 with SMTP id j11mr3868435wxc;
4582         Fri, 02 Dec 2005 10:00:56 -0800 (PST)
4583 Received: by 10.70.91.15 with HTTP; Fri, 2 Dec 2005 10:00:56 -0800 (PST)
4584 Message-ID: <8b1e030f0512021000x5b5edfd9pa6062f8f49563d80@mail.gmail.com>
4585 Date: Fri, 2 Dec 2005 10:00:56 -0800
4586 From: Laurel Fan <laurel.fan@gmail.com>
4587 To: Anne G <anne@wjh.harvard.edu>
4588 Subject: Re: [Courses] [Ruby] Lesson 1: Classes
4589 In-Reply-To: <Pine.SOL.4.30.0512010807500.20462-100000@wjh1.wjh.harvard.edu>
4590 MIME-Version: 1.0
4591 Content-Type: text/plain; charset=ISO-8859-1
4592 Content-Transfer-Encoding: quoted-printable
4593 Content-Disposition: inline
4594 References: <Pine.SOL.4.30.0512010807500.20462-100000@wjh1.wjh.harvard.edu>
4595 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
4596 X-Topics: Introduction to Ruby
4597 Cc: courses@linuxchix.org
4598 X-BeenThere: courses@linuxchix.org
4599 X-Mailman-Version: 2.1.5
4600 Precedence: list
4601 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
4602 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4603         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
4604 List-Archive: <http://linuxchix.org/pipermail/courses>
4605 List-Post: <mailto:courses@linuxchix.org>
4606 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
4607 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4608         <mailto:courses-request@linuxchix.org?subject=subscribe>
4609 X-List-Received-Date: Fri, 02 Dec 2005 18:01:00 -0000
4610 Content-Length: 4226
4611 Lines: 140
4613 On 12/1/05, Anne G <anne@wjh.harvard.edu> wrote:
4614 > Thank you so much Laurel for your response. I will review
4615 > classes, and do the reading on lesson2 as you suggested.
4617 > First of all your suggestion expended my thinking to include
4618 > passing of an object. Thank you so much.
4620 > datainst.lookforX(infoinst)
4622 > I took this idea and tried to generalize it to 3 objects:
4624 > object1 -- stores data,  calls on object2 -- stores first
4625 > type of info, calls on object3 -- stores 2nd type of info,
4626 > calls back on object1.
4628 > I found myself doing the following:
4630 > storeobject.lookforX(info1object,info2object,storeobject)
4632 > this way lookforX knows to call on info1object
4633 > info1object knows to call on info2object
4634 > info2object knows to call on storeobject
4635 > ...
4637 > I love this solution because it is totally within the scope
4638 > of what I can do. but it is a bit heavy and still smacks of
4639 > procedural in that I have to figure out what the whole chain
4640 > of objects will be instead of just relation between
4641 > pairs of objects.
4643 > Is this the way your suggestion would work with 3 objects?
4645 All of these objects can store information.  So you could pass in the
4646 other object once, and then the object can save it to use later.  So
4647 for example, when you instantiate the objects, you could do:
4649 -----
4651 storeObject =3D StoreObject.new()
4652 infoInst1 =3D InfoObject.new()
4653 infoInst2 =3D InfoObject.new()
4655 infoInst1.helper =3D infoInst2
4656 infoInst2.helper =3D storeObject
4658 infoInst1.lookForX # we don't need to pass the other objects here,
4659 because it remembered it from above
4661 -----
4662 The setHelper function itself remembers its argument with an @
4663 variable, something like:
4664 -----
4665 classInfoObject
4667 attr_accessor :helper # this makes a method helper that allows you do
4668 set the variable @helper
4672 -----
4673 And then lookForX would look kind of like
4674 -----
4675 def lookForX
4676    ...
4677    @helper.lookForX
4678    ...
4682 > ---------------------------------------------------------
4684 > I found this recent discussion
4685 > http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/68acf0f7c=
4686 8a95138/1bbd14c18a57a45b#1bbd14c18a57a45b
4688 > Daniel Schierbeck offered a structure which seems simple
4689 > enough, and probably similar to yours, but it is a bit
4690 > confusing to my beginner's eye. What is hapening?
4692 > Here is what he said
4694 > Say you have three classes, A, B, and C, and you want their
4695 > instances to be able to communicate. These three classes
4696 > will all be instantiated together, so we know that the other
4697 > objects are there. You then write a class, let's just call
4698 > it Base, that you instantiate instead of the three classes.
4699 > It will instantiate them instead, and pass a reference to
4700 > itself to each of them.
4702 >    class Base
4703 >      attr_reader :a, :b, :c
4705 >      def initialize
4706 >        @a, @b, @c =3D A.new(self), B.new(self), C.new(self)
4707 >      end
4709 >      # We'll keep the other classes in here, so we don't
4710 >      # pollute the main namespace
4711 >      class A
4712 >        def initialize(base)
4713 >          @base =3D base
4714 >          @b, @c =3D base.b, base.c
4715 >        end
4716 >      end
4718 >      class B
4719 >        def initialize(base)
4720 >          @base =3D base
4721 >          @a, @c =3D base.a, base.c
4722 >        end
4723 >      end
4725 >      class C
4726 >        def initialize(base)
4727 >          @base =3D base
4728 >          @a, @b =3D base.a, base.b
4729 >        end
4730 >      end
4731 >    end
4733 > How would I use this in my expended task:
4734 > objectA needing to call on objectB needing to call on
4735 > objectC needing to call back on objectA
4737 This is pretty similar to what I wrote above, but it looks nicer
4738 because all the initialization happens inside the Base class.  In the
4739 above code, the initialization took 5 lines.  It would have been even
4740 more if every object had to know about every other object.  If the
4741 same sort of thing had to be written multiple times, it's a lot nicer
4742 to put it all in one place so we don't have to repeat it.
4744 To use this in your case, replace the call for lookForInst on the
4745 object that you passed in with a call for lookForInst on one of the
4746 member variables (like @a, @b, @c...).  You'll probably find that you
4747 don't have to pass the objects in, so your code wil look much less
4748 procedural.
4751 Laurel Fan
4752 http://dreadnought.gorgorg.org
4754 From laurel.fan@gmail.com  Wed Nov 30 09:07:25 2005
4755 Return-Path: <laurel.fan@gmail.com>
4756 X-Original-To: courses@linuxchix.org
4757 Delivered-To: courses@linuxchix.org
4758 Received: from localhost (localhost [127.0.0.1])
4759         by www.linuxchix.org (Postfix) with ESMTP id 228CC27321E
4760         for <courses@linuxchix.org>; Wed, 30 Nov 2005 09:07:25 +1100 (EST)
4761 Received: from www.linuxchix.org ([127.0.0.1])
4762         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
4763         id 03208-10 for <courses@linuxchix.org>;
4764         Wed, 30 Nov 2005 09:07:25 +1100 (EST)
4765 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.195])
4766         by www.linuxchix.org (Postfix) with ESMTP id 2A53727321A
4767         for <courses@linuxchix.org>; Wed, 30 Nov 2005 09:07:23 +1100 (EST)
4768 Received: by xproxy.gmail.com with SMTP id s9so44882wxc
4769         for <courses@linuxchix.org>; Tue, 29 Nov 2005 14:07:16 -0800 (PST)
4770 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
4771         h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
4772         b=VnNJshTHpn7+xbXQ59OgRaOLM7NRo2j0rsIzefvZLvnc0BCuPUw9BOp4Q5OqKwvhvBj/0oBGps7/5WokUBQhWjiGKLzSBT7URtv3wQcevUs9qURzzpgRCQe/ZYoPLRTAFaMYr8GSieFSk8YrYNA7Hod1dEXQ2iKS15YLG8WZquU=
4773 Received: by 10.70.113.3 with SMTP id l3mr253837wxc;
4774         Tue, 29 Nov 2005 14:07:16 -0800 (PST)
4775 Received: by 10.70.91.15 with HTTP; Tue, 29 Nov 2005 14:07:16 -0800 (PST)
4776 Message-ID: <8b1e030f0511291407n5e56336asce839753a018e03d@mail.gmail.com>
4777 Date: Tue, 29 Nov 2005 14:07:16 -0800
4778 From: Laurel Fan <laurel.fan@gmail.com>
4779 To: courses@linuxchix.org
4780 MIME-Version: 1.0
4781 Content-Type: text/plain; charset=ISO-8859-1
4782 Content-Transfer-Encoding: quoted-printable
4783 Content-Disposition: inline
4784 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
4785 X-Topics: Introduction to Ruby
4786 Subject: [Courses] [Ruby] Lesson 2: Containers, Blocks, and Iterators;
4787         Standard Types; More About Methods
4788 X-BeenThere: courses@linuxchix.org
4789 X-Mailman-Version: 2.1.5
4790 Precedence: list
4791 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
4792 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4793         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
4794 List-Archive: <http://linuxchix.org/pipermail/courses>
4795 List-Post: <mailto:courses@linuxchix.org>
4796 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
4797 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
4798         <mailto:courses-request@linuxchix.org?subject=subscribe>
4799 X-List-Received-Date: Tue, 29 Nov 2005 22:07:25 -0000
4800 Content-Length: 5447
4801 Lines: 196
4803 =3D Lesson 2: Containers, Blocks, and Iterators; Standard Types; More
4804 About Methods
4806 =3D=3D Reading
4808 If you're using the paper or pdf 2nd edition, the reading is chapters
4809 4-6, pages 40 to 80.
4811 If you're using the online 1st edition, the reading is:
4813 http://www.rubycentral.com/book/tut_containers.html
4814 http://www.rubycentral.com/book/tut_stdtypes.html
4815 http://www.rubycentral.com/book/tut_methods.html
4817 With the last lesson, Akkana was wondering when yield and blocks were
4818 useful, and Anne had asked about how objects could send messages to
4819 other objects.  These readings will hopefully provide some more
4820 information about these topics.
4822 Here are two more pages that might be useful:
4824 Ruby idioms: http://www.rubygarden.org/ruby?RubyIdioms
4825 Provides a few elegant ways to do common things in Ruby.
4827 Annotated Ruby docs: http://ruby.outertrack.com/
4828 Read and leave comments and annotations on the standard documentation.
4830 =3D=3D Homework
4832 =3D=3D=3D Questions
4834 0. Same as last time, is there anything you didn't understand?  would
4835    like to learn more about?
4837 1. How many different ways can you think of to write the
4838    following string declaration code?
4839 ----
4840 name =3D "Laurel"
4841 ----
4843    There are plenty of ways to answer this, so be creative :)
4845 2. What are the 4 things you can specify when calling a method?  In
4846    what situations are each of them optional, not allowed, or
4847    mandatory?
4849 3. What does this do?
4851 (first, second, third) =3D "1 2 3".split(/ /)
4853 p first + third
4855 =3D=3D=3D Problems
4857 1. Blocks and iterators:
4859 Rewrite the findLongWords method below using iterators and blocks
4860 instead of the for loop:
4862 ----
4863 # Given an array of words, findLongWords returns a new array
4864 # containing the words with more than 5 letters.
4865 def findLongWords(words)
4866   longWords =3D Array.new()
4867   for i in 0...words.length
4868     if !words[i].nil? && words[i].length > 5 # long words have more
4869 than 5 letters
4870       longWords << words[i]
4871     end
4872   end
4873   longWords
4876 p findLongWords(['thisOneIsLong', 'short', 'howAboutThisOne' ])
4877 ----
4879 Hint: look at the documentation for the Enumerable module:
4880 http://www.ruby-doc.org/core/classes/Enumerable.html
4882 2. Blocks and sort
4884 Normally, if you call sort on an array of strings, it'll sort by their
4885 lexical value (ie. alphabetically).  Write some code that will sort an
4886 array of strings first by number of vowels (fewest first), and then by
4887 lexical value (for strings of the same length.  For the sake of this
4888 problem, let's say that a, e, i, o, and u are the only vowels.
4890 For example:
4892 Normal sort would do:
4894 ['dog', 'cat', 'aardvark', 'bird'].sort
4895 #=3D> ['aardvark', 'bird', 'cat', 'dog']
4897 Your code should return:
4899 ['bird', 'cat', 'dog', 'aardvark']
4901 You can use the Enumerable.sort function:
4902 http://www.ruby-doc.org/core/classes/Enumerable.html#M001944
4904 Bonus: use Enumerable.sort_by:
4905 http://www.ruby-doc.org/core/classes/Enumerable.html#M001945
4906 (the example at the link above)
4908 3. Implement some methods
4910 Below is a skeleton class definition for the /proc information class
4911 we talked about in the last lesson.  Implement the blank methods.
4913 ----
4914 class ProcessInfo
4915   # initialize a ProcessInfo object with:
4916   # pid      process id
4917   # cmdline  complete command line of the process
4918   # cwd      name of the working directory of the process
4919   # exe      filename of the executable program
4920   # files    array of files that the process has open
4921   def initialize(pid, cmdline, cwd, exe, files)
4922     # Please implement
4923   end
4925   # calls the given block once for each open file, passing the file
4926   # name as a parameter.
4927   def each_open_file
4928     # Please implement
4929   end
4931   # add the provided file names to the process' list of open files
4932   def add_open_files(*new_files)
4933     # Please implement
4934   end
4936   # return a string representation of the process information
4937   def to_s
4938     # Please implement
4939   end
4943 ### test code
4945 test_process =3D ProcessInfo.new(20,
4946                      "emacs -nw my_program.rb my_library.rb",
4947                      "/home/laurel",
4948                      "/usr/bin/emacs",
4949                      ["/home/laurel/my_program.rb",
4950 "/home/laurel/my_library.rb"]);
4952 print "Before adding files:\n"
4953 print test_process.to_s
4954 print "Process #{test_process.pid} has the following files open:\n"
4955 test_process.each_open_file do |open_file|
4956   print " - #{open_file}\n"
4959 test_process.add_open_files("/home/laurel/another.rb", "/home/laurel/more.r=
4962 print "\nAfter adding files:\n"
4963 print test_process.to_s
4964 print "Process #{test_process.pid} has the following files open:\n"
4965 test_process.each_open_file do |open_file|
4966   print " - #{open_file}\n"
4969 ----
4971 The output of the test code should look something like:
4973 ----
4974 Before adding files:
4975 20: emacs -nw my_program.rb my_library.rb
4976  cwd=3D/home/laurel, exe=3D/usr/bin/emacs, 2 open files
4977 Process 20 has the following files open:
4978  - /home/laurel/my_program.rb
4979  - /home/laurel/my_library.rb
4981 After adding files:
4982 20: emacs -nw my_program.rb my_library.rb
4983  cwd=3D/home/laurel, exe=3D/usr/bin/emacs, 4 open files
4984 Process 20 has the following files open:
4985  - /home/laurel/my_program.rb
4986  - /home/laurel/my_library.rb
4987  - /home/laurel/another.rb
4988  - /home/laurel/more.rb
4989 ----
4991 Bonus: I don't think the constructor is very nice to use.  I have to
4992 remember all of the arguments and what order they're in, so it's easy
4993 to make a mistake and end up with the cmdline as the cwd, etc.  What
4994 are some other ways you could write it?
4997 Laurel Fan
4998 http://dreadnought.gorgorg.org
5000 From anne@wjh.harvard.edu  Sun Dec  4 02:58:52 2005
5001 Return-Path: <anne@wjh.harvard.edu>
5002 X-Original-To: courses@linuxchix.org
5003 Delivered-To: courses@linuxchix.org
5004 Received: from localhost (localhost [127.0.0.1])
5005         by www.linuxchix.org (Postfix) with ESMTP id AD98027323C
5006         for <courses@linuxchix.org>; Sun,  4 Dec 2005 02:58:52 +1100 (EST)
5007 Received: from www.linuxchix.org ([127.0.0.1])
5008         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
5009         id 09780-10 for <courses@linuxchix.org>;
5010         Sun, 4 Dec 2005 02:58:52 +1100 (EST)
5011 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
5012         by www.linuxchix.org (Postfix) with ESMTP id 9B19D273231
5013         for <courses@linuxchix.org>; Sun,  4 Dec 2005 02:58:51 +1100 (EST)
5014 Received: from localhost (anne@localhost)
5015         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jB3FwiW24072
5016         for <courses@linuxchix.org>; Sat, 3 Dec 2005 10:58:44 -0500 (EST)
5017 Date: Sat, 3 Dec 2005 10:58:44 -0500 (EST)
5018 From: Anne G <anne@wjh.harvard.edu>
5019 To: <courses@linuxchix.org>
5020 Subject: [Courses] [Ruby] Lesson 2: Iterators 
5021 Message-ID: <Pine.SOL.4.30.0512031040370.23246-100000@wjh1.wjh.harvard.edu>
5022 MIME-Version: 1.0
5023 Content-Type: TEXT/PLAIN; charset=US-ASCII
5024 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
5025 X-Topics: Introduction to Ruby
5026 X-BeenThere: courses@linuxchix.org
5027 X-Mailman-Version: 2.1.5
5028 Precedence: list
5029 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
5030 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5031         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
5032 List-Archive: <http://linuxchix.org/pipermail/courses>
5033 List-Post: <mailto:courses@linuxchix.org>
5034 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
5035 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5036         <mailto:courses-request@linuxchix.org?subject=subscribe>
5037 X-List-Received-Date: Sat, 03 Dec 2005 15:58:53 -0000
5038 Content-Length: 1793
5039 Lines: 60
5041 Hi Laurel,
5043 Thank you so much for helping with my example, so I only
5044 have to grasp the ruby points.
5046 I understood your example with the objecthelper. When I
5047 tried to compile it, I got some error regarding my recursion
5048 with lookforXs.
5050 in `notEndofData?': stack level too deep (SystemStackError)
5051    from /Users/anne/Desktop/dudruby8d.rb:39:in lookforX'
5053 I tried to use catch and throw, but it did not change the
5054 error. How do I break from a recursion like mine?
5055 Here is the method which calls lookforX with catch/throw
5057 def getinfo
5058     # the first time we run this method, we are in a block,
5059     # and we store the data
5060         if self.notendofblock?
5061               @storeArr.push(writeline)
5062               self.increasind
5063               self.getinfo
5064     # after a while we reach the end of the block
5065     # and look for a new one
5066         else
5067               catch(:myrecursion) do
5068                    self.lookforX
5069               end
5070         end
5073 And here is lookforX
5075 def lookforX
5076          if self.notEndofData?
5077                 # We found the keyword that starts a subject
5078                 if self.trial?
5079                     @helper.getinfo    # go store some info
5080                     throw :myrecursion # break out
5081                 # or we keep looking for the keyword
5082                 else
5083                     self.lookforX
5084                 end
5085          else   #end of file, we are done
5086                 throw :myrecursion
5087          end
5090 actually I have two recursions, lookforX method calls for
5091 self.lookforX method, and getinfo calls for self.getinfo.
5092 So maybe I need to break out of both recursions?
5094 Is the use of recursions like this to be avoided?  my use of
5095 catch and throw is not very elegant here, running across two
5096 methods. Can it be used better? Is the alternative to use a
5097 loop?
5102 From anne@wjh.harvard.edu  Sun Dec  4 12:24:55 2005
5103 Return-Path: <anne@wjh.harvard.edu>
5104 X-Original-To: courses@linuxchix.org
5105 Delivered-To: courses@linuxchix.org
5106 Received: from localhost (localhost [127.0.0.1])
5107         by www.linuxchix.org (Postfix) with ESMTP id B72A227324F
5108         for <courses@linuxchix.org>; Sun,  4 Dec 2005 12:24:55 +1100 (EST)
5109 Received: from www.linuxchix.org ([127.0.0.1])
5110         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
5111         id 13686-01 for <courses@linuxchix.org>;
5112         Sun, 4 Dec 2005 12:24:55 +1100 (EST)
5113 Received: from wjh2.wjh.harvard.edu (wjh2.wjh.harvard.edu [140.247.94.249])
5114         by www.linuxchix.org (Postfix) with ESMTP id 862D0273236
5115         for <courses@linuxchix.org>; Sun,  4 Dec 2005 12:24:54 +1100 (EST)
5116 Received: from localhost (anne@localhost)
5117         by wjh2.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jB41OnH22320
5118         for <courses@linuxchix.org>; Sat, 3 Dec 2005 20:24:49 -0500 (EST)
5119 Date: Sat, 3 Dec 2005 20:24:48 -0500 (EST)
5120 From: Anne G <anne@wjh.harvard.edu>
5121 To: <courses@linuxchix.org>
5122 Subject: Re: [Courses] [Ruby] Lesson 2: Iterators 
5123 In-Reply-To: <Pine.SOL.4.30.0512031040370.23246-100000@wjh1.wjh.harvard.edu>
5124 Message-ID: <Pine.SOL.4.30.0512032016030.22112-100000@wjh2.wjh.harvard.edu>
5125 MIME-Version: 1.0
5126 Content-Type: TEXT/PLAIN; charset=US-ASCII
5127 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
5128 X-Topics: Introduction to Ruby
5129 X-BeenThere: courses@linuxchix.org
5130 X-Mailman-Version: 2.1.5
5131 Precedence: list
5132 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
5133 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5134         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
5135 List-Archive: <http://linuxchix.org/pipermail/courses>
5136 List-Post: <mailto:courses@linuxchix.org>
5137 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
5138 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5139         <mailto:courses-request@linuxchix.org?subject=subscribe>
5140 X-List-Received-Date: Sun, 04 Dec 2005 01:24:56 -0000
5141 Content-Length: 3324
5142 Lines: 104
5144 I think I fixed the problem with the lookforX recursion,
5145 --- the code never reached the throw command in my first try
5146 because helper.getinfo moved to objectinfo1, objectinfo2,
5147 and back to objectstore...
5148 --- Even with this problem fixed, the getinfo recursion
5149 reaches too many levels. getinfo calls getinfo through the
5150 info objects, which calls getinfo...
5152 def lookforX
5153          throw :myrecursion if self.trial?
5154          self.increaseind
5157 def getinfo
5158      if self.notendofblock?  # we are in a block, store the data
5159               @storeArr.push(self.tokeep)
5160               self.increaseind
5161               self.getinfo
5162     else   # we reached the end of a block, look for a new one.
5163              catch(:myrecursion) do
5164                    while self.notendofData?
5165                         self.lookforX
5166                    end
5167                    break
5168               end
5169               @helper.getinfo if self.trial?
5170      end
5173 What I wanted was three independent objects which did their
5174 bit and told each other when to get started, but in the
5175 actual implementation, it does not work I think because the
5176 three objects are not actually independent. Each time we
5177 call on an object, we tie a know which we have to untie at
5178 some point.
5180 On Sat, 3 Dec 2005, Anne G wrote:
5182 > Hi Laurel,
5184 > Thank you so much for helping with my example, so I only
5185 > have to grasp the ruby points.
5187 > I understood your example with the objecthelper. When I
5188 > tried to compile it, I got some error regarding my recursion
5189 > with lookforXs.
5191 > in `notEndofData?': stack level too deep (SystemStackError)
5192 >    from /Users/anne/Desktop/dudruby8d.rb:39:in lookforX'
5194 > I tried to use catch and throw, but it did not change the
5195 > error. How do I break from a recursion like mine?
5196 > Here is the method which calls lookforX with catch/throw
5198 > def getinfo
5199 >     # the first time we run this method, we are in a block,
5200 >     # and we store the data
5201 >         if self.notendofblock?
5202 >               @storeArr.push(writeline)
5203 >               self.increasind
5204 >               self.getinfo
5205 >     # after a while we reach the end of the block
5206 >     # and look for a new one
5207 >         else
5208 >               catch(:myrecursion) do
5209 >                    self.lookforX
5210 >               end
5211 >         end
5212 > end
5214 > And here is lookforX
5216 > def lookforX
5217 >          if self.notEndofData?
5218 >                 # We found the keyword that starts a subject
5219 >                 if self.trial?
5220 >                     @helper.getinfo    # go store some info
5221 >                     throw :myrecursion # break out
5222 >                 # or we keep looking for the keyword
5223 >                 else
5224 >                     self.lookforX
5225 >                 end
5226 >          else   #end of file, we are done
5227 >                 throw :myrecursion
5228 >          end
5229 > end
5231 > actually I have two recursions, lookforX method calls for
5232 > self.lookforX method, and getinfo calls for self.getinfo.
5233 > So maybe I need to break out of both recursions?
5235 > Is the use of recursions like this to be avoided?  my use of
5236 > catch and throw is not very elegant here, running across two
5237 > methods. Can it be used better? Is the alternative to use a
5238 > loop?
5242 > _______________________________________________
5243 > Courses mailing list
5244 > Courses@linuxchix.org
5245 > http://mailman.linuxchix.org/mailman/listinfo/courses
5249 From jennyw@dangerousideas.com  Fri Dec  9 18:56:32 2005
5250 Return-Path: <jennyw@dangerousideas.com>
5251 X-Original-To: courses@linuxchix.org
5252 Delivered-To: courses@linuxchix.org
5253 Received: from localhost (localhost [127.0.0.1])
5254         by www.linuxchix.org (Postfix) with ESMTP id C0231273232
5255         for <courses@linuxchix.org>; Fri,  9 Dec 2005 18:56:32 +1100 (EST)
5256 Received: from www.linuxchix.org ([127.0.0.1])
5257         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
5258         id 31941-07 for <courses@linuxchix.org>;
5259         Fri, 9 Dec 2005 18:56:32 +1100 (EST)
5260 X-Greylist: delayed 1576 seconds by postgrey-1.21 at nest;
5261         Fri, 09 Dec 2005 18:56:32 EST
5262 Received: from relay1.mail.twtelecom.net (relay1.mail.twtelecom.net
5263         [216.136.102.250])
5264         by www.linuxchix.org (Postfix) with ESMTP id 57DC227322A
5265         for <courses@linuxchix.org>; Fri,  9 Dec 2005 18:56:32 +1100 (EST)
5266 Received: from [10.0.1.2] (unknown [66.194.95.2])
5267         by relay1.mail.twtelecom.net (Postfix) with ESMTP id 810B9A51F;
5268         Fri,  9 Dec 2005 01:25:07 -0600 (CST)
5269 Message-ID: <4399327E.9040608@dangerousideas.com>
5270 Date: Fri, 09 Dec 2005 01:30:06 -0600
5271 From: jennyw <jennyw@dangerousideas.com>
5272 User-Agent: Mozilla Thunderbird 1.0.7 (Macintosh/20050923)
5273 X-Accept-Language: en-us, en
5274 MIME-Version: 1.0
5275 To: Anne G <anne@wjh.harvard.edu>
5276 Subject: Re: [Courses] [Ruby] Lesson 2: Iterators
5277 References: <Pine.SOL.4.30.0512032016030.22112-100000@wjh2.wjh.harvard.edu>
5278 In-Reply-To: <Pine.SOL.4.30.0512032016030.22112-100000@wjh2.wjh.harvard.edu>
5279 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
5280 Content-Transfer-Encoding: 7bit
5281 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
5282 X-Topics: Introduction to Ruby
5283 Cc: courses@linuxchix.org
5284 X-BeenThere: courses@linuxchix.org
5285 X-Mailman-Version: 2.1.5
5286 Precedence: list
5287 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
5288 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5289         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
5290 List-Archive: <http://linuxchix.org/pipermail/courses>
5291 List-Post: <mailto:courses@linuxchix.org>
5292 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
5293 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5294         <mailto:courses-request@linuxchix.org?subject=subscribe>
5295 X-List-Received-Date: Fri, 09 Dec 2005 07:56:33 -0000
5296 Content-Length: 1778
5297 Lines: 41
5299 Anne G wrote:
5301 >What I wanted was three independent objects which did their
5302 >bit and told each other when to get started, but in the
5303 >actual implementation, it does not work I think because the
5304 >three objects are not actually independent. Each time we
5305 >call on an object, we tie a know which we have to untie at
5306 >some point.
5307 >  
5309 Hi, Anne,
5311 I went back and read through your e-mails ... I wasn't sure what you're 
5312 trying to accomplish with the three objects. Is this an abstract example 
5313 or is there a practical application? It looked very abstract to me, so 
5314 it was hard to figure out what you're trying to accomplish.
5316 Going back, I see you were asking how to send messages to objects. You 
5317 just do it like this ... object.message. For example,
5319 fruits = ['apple', 'pear', 'banana'] #  an array of fruits
5320 fruits.first     # send the message #first to the fruits object. it 
5321 returns a string: 'apple'
5322 fruits.first.class # you can also send two messages in a row -- for 
5323 example, this sends #class to 'apple'. It'll return the class, String.
5325 You also asked how can you can have two objects that do things and ask 
5326 each other to do something. I see that you have the objects calling each 
5327 other, and some recursive methods, but this is all implementation -- 
5328 what I'm not clear on is the problem that this is the proposed solution 
5329 for. I don't think this is so much a Ruby thing as it is a design 
5330 issue.  It could well be that there's a design pattern that matches 
5331 exactly what you want to do -- if we figure out what that is, it should 
5332 be a lot easier to show it in Ruby.  I guess the first step might be to 
5333 come up with a practical example (i.e. a user story). You might have 
5334 done this, of course, and I may have missed it, so apologies if that's so.
5336 Good luck!
5341 From anne@wjh.harvard.edu  Fri Dec  9 22:43:54 2005
5342 Return-Path: <anne@wjh.harvard.edu>
5343 X-Original-To: courses@linuxchix.org
5344 Delivered-To: courses@linuxchix.org
5345 Received: from localhost (localhost [127.0.0.1])
5346         by www.linuxchix.org (Postfix) with ESMTP id E821A273238
5347         for <courses@linuxchix.org>; Fri,  9 Dec 2005 22:43:53 +1100 (EST)
5348 Received: from www.linuxchix.org ([127.0.0.1])
5349         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
5350         id 00944-06 for <courses@linuxchix.org>;
5351         Fri, 9 Dec 2005 22:43:53 +1100 (EST)
5352 Received: from wjh2.wjh.harvard.edu (wjh2.wjh.harvard.edu [140.247.94.249])
5353         by www.linuxchix.org (Postfix) with ESMTP id E06D4273226
5354         for <courses@linuxchix.org>; Fri,  9 Dec 2005 22:43:52 +1100 (EST)
5355 Received: from localhost (anne@localhost)
5356         by wjh2.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jB9BhiB24930;
5357         Fri, 9 Dec 2005 06:43:44 -0500 (EST)
5358 Date: Fri, 9 Dec 2005 06:43:44 -0500 (EST)
5359 From: Anne G <anne@wjh.harvard.edu>
5360 To: jennyw <jennyw@dangerousideas.com>
5361 Subject: Re: [Courses] [Ruby] Lesson 2: Iterators
5362 In-Reply-To: <4399327E.9040608@dangerousideas.com>
5363 Message-ID: <Pine.SOL.4.30.0512090600080.21194-100000@wjh2.wjh.harvard.edu>
5364 MIME-Version: 1.0
5365 Content-Type: TEXT/PLAIN; charset=US-ASCII
5366 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
5367 X-Topics: Introduction to Ruby
5368 Cc: courses@linuxchix.org
5369 X-BeenThere: courses@linuxchix.org
5370 X-Mailman-Version: 2.1.5
5371 Precedence: list
5372 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
5373 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5374         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
5375 List-Archive: <http://linuxchix.org/pipermail/courses>
5376 List-Post: <mailto:courses@linuxchix.org>
5377 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
5378 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5379         <mailto:courses-request@linuxchix.org?subject=subscribe>
5380 X-List-Received-Date: Fri, 09 Dec 2005 11:43:54 -0000
5381 Content-Length: 3833
5382 Lines: 106
5386 Thank you for your response
5388 > I don't think this is so much a Ruby thing as it is a
5389 > design issue.
5390 Yes, I want to understand object oriented programming
5391 thinking. I started with objective C and cocoa, but I was
5392 frustrated with it and not learning any OOP. Ruby is so much
5393 easier, I can get to the methodology.
5395 > Is this an abstract example or is there a practical
5396 > application?
5397 What I want to learn is abstract, the example I chose to
5398 learn with - which might not be the best - is concrete.
5400 As I understand it, in procedural programming, which is what
5401 I have been doing, I write code thinking all along of time.
5402 The code does this, then this, then this... in a thread.
5404 In OO programming, it is more like a state machine in
5405 digital electronic. All I need to know is the state of the
5406 object, and what it will do if it gets some info. So I
5407 should be able to define things locally only, and the whole
5408 thing should work based on logic more than time.
5410 The concrete example I took is an archive file with 20000
5411 lines of data from 200 subjects in an experiment. The
5412 procedure way, I read the file line by line, and with ifs,
5413 switches etc, I tell it what to do to extract the info I
5414 want from the data file.  The OO P way, I have three
5415 objects, each specializing in a particular aspect of the
5416 data, and they call on each other once they are done with
5417 their part.
5419 > fruits = ['apple', 'pear', 'banana'] # an array of
5420 > fruits fruits.first # send the message #first to the
5421 > fruits object. it returns a string: 'apple'
5423 This is how objects and messages are first explained. But my
5424 question is at one level of abstraction higher: In most
5425 examples, the methods are defined in a class when the
5426 instances of the objects are not yet defined.
5428 In my case, How will the object which stores the actual
5429 subject data tell the object which stores the subject's id
5430 that the next line in the file is for it to process, when
5431 neither object is around at the time of the method
5432 definition.
5434 Laurel came up with a class object @helper which will
5435 contain the instantiated object to be called at execution.
5437 This worked very well, getdata calls getinfo1 which calls
5438 getinfo2 which calls getdata ad infinitum. The problem I
5439 encounted is that ad infinitum is not supported by my
5440 implementation of Ruby, I got an error message, too many
5441 levels (each repeat call on getdata is a level).
5443 Of course I can find ways to write the code more efficiently
5444 to avoid the limit, but by calling a method for each line of
5445 code, I encountered a limit, and the fact that the limit
5446 exists is what bothers me. That means I have to make sure
5447 the whole program is done is so many calls.  This is not a
5448 stable timeless implementation. It could not run on live
5449 data that kept coming and coming.
5451 It is probably because I am doing something wrong
5452 in my object communication, but I don't know what it is.
5454 ---------------------------------------------------------
5456 as for the general problem as to how to get objects to
5457 communicate, here is an answer I received, which I haven't
5458 figured out how to use in my own 3 object example.
5460 Partly, most objects communicate only with objects they
5461 create and the object that created them.
5463 class A
5464   def initialize
5465     arr=[1,2,3,4]
5466     arr.last
5467   end
5468   def ask
5469     return arr.first
5470   end
5473 a=A.new
5474 last=a.ask
5476 Here the object we are currently in creates an object a of
5477 class A, it communicates with this object with a.ask. The
5478 object a itself creates an Object arr and also communicates
5479 with that. This is the way most object communicate with each
5480 other.
5482 If you need two object (A and B) that are created by a third
5483 object (C)  to communicate with each other then you are
5484 probably doing something wrong (although not always) and it
5485 might have been better if Object A had created object B
5486 instead of letting Object C create both.
5491 From laurel.fan@gmail.com  Sat Dec 10 04:13:26 2005
5492 Return-Path: <laurel.fan@gmail.com>
5493 X-Original-To: courses@linuxchix.org
5494 Delivered-To: courses@linuxchix.org
5495 Received: from localhost (localhost [127.0.0.1])
5496         by www.linuxchix.org (Postfix) with ESMTP id 691E4273241
5497         for <courses@linuxchix.org>; Sat, 10 Dec 2005 04:13:26 +1100 (EST)
5498 Received: from www.linuxchix.org ([127.0.0.1])
5499         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
5500         id 03178-01 for <courses@linuxchix.org>;
5501         Sat, 10 Dec 2005 04:13:26 +1100 (EST)
5502 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.202])
5503         by www.linuxchix.org (Postfix) with ESMTP id 9E976273227
5504         for <courses@linuxchix.org>; Sat, 10 Dec 2005 04:13:25 +1100 (EST)
5505 Received: by xproxy.gmail.com with SMTP id h31so628834wxd
5506         for <courses@linuxchix.org>; Fri, 09 Dec 2005 09:13:17 -0800 (PST)
5507 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
5508         h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
5509         b=hMExDahSLKz8nQENi52lSZxqxKGIjdgafq+TtaYiXVicxsXocCr+pEEfbpLTjeCYuVsjZR0yLAa1GYnRX1FZo6k6mSJ+ipt7j+6z8qJKB+3wnuLWo61gChWAQMZy/EfZ8Zc2EfWxRZaJy7YOfPsqkqMoDUEU4OIVpeSnh9WZiDA=
5510 Received: by 10.70.122.11 with SMTP id u11mr164101wxc;
5511         Fri, 09 Dec 2005 09:13:17 -0800 (PST)
5512 Received: by 10.70.91.15 with HTTP; Fri, 9 Dec 2005 09:13:17 -0800 (PST)
5513 Message-ID: <8b1e030f0512090913k7c4930f9gbfa84774d424751@mail.gmail.com>
5514 Date: Fri, 9 Dec 2005 09:13:17 -0800
5515 From: Laurel Fan <laurel.fan@gmail.com>
5516 To: Anne G <anne@wjh.harvard.edu>
5517 Subject: Re: [Courses] [Ruby] Lesson 2: Iterators
5518 In-Reply-To: <Pine.SOL.4.30.0512090600080.21194-100000@wjh2.wjh.harvard.edu>
5519 MIME-Version: 1.0
5520 Content-Type: text/plain; charset=ISO-8859-1
5521 Content-Transfer-Encoding: quoted-printable
5522 Content-Disposition: inline
5523 References: <4399327E.9040608@dangerousideas.com>
5524         <Pine.SOL.4.30.0512090600080.21194-100000@wjh2.wjh.harvard.edu>
5525 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
5526 X-Topics: Introduction to Ruby
5527 Cc: jennyw <jennyw@dangerousideas.com>, courses@linuxchix.org
5528 X-BeenThere: courses@linuxchix.org
5529 X-Mailman-Version: 2.1.5
5530 Precedence: list
5531 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
5532 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5533         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
5534 List-Archive: <http://linuxchix.org/pipermail/courses>
5535 List-Post: <mailto:courses@linuxchix.org>
5536 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
5537 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5538         <mailto:courses-request@linuxchix.org?subject=subscribe>
5539 X-List-Received-Date: Fri, 09 Dec 2005 17:13:26 -0000
5540 Content-Length: 1408
5541 Lines: 33
5543 On 12/9/05, Anne G <anne@wjh.harvard.edu> wrote:
5544 > This worked very well, getdata calls getinfo1 which calls
5545 > getinfo2 which calls getdata ad infinitum. The problem I
5546 > encounted is that ad infinitum is not supported by my
5547 > implementation of Ruby, I got an error message, too many
5548 > levels (each repeat call on getdata is a level).
5550 > Of course I can find ways to write the code more efficiently
5551 > to avoid the limit, but by calling a method for each line of
5552 > code, I encountered a limit, and the fact that the limit
5553 > exists is what bothers me. That means I have to make sure
5554 > the whole program is done is so many calls.  This is not a
5555 > stable timeless implementation. It could not run on live
5556 > data that kept coming and coming.
5558 Now I think I understand a bit more of what the problem is.
5560 Recursion (methods calling themselves) might not be the best solution
5561 for data that keeps coming continuously.  Each recursive method call
5562 causes a little bit of overhead (it needs to keep track of every
5563 method currently running), and this can add up over time.
5565 It's also possible that there's a bug in the code causing an infinite
5566 recursion loop.
5568 Without seeing all of your code, it's hard to tell what exactly the
5569 problem is, or whether there would be a better way to implement it
5570 without recursion.  Would you be willing to post the whole thing to
5571 the list?
5574 Laurel Fan
5575 http://dreadnought.gorgorg.org
5577 From anne@wjh.harvard.edu  Sat Dec 10 06:48:13 2005
5578 Return-Path: <anne@wjh.harvard.edu>
5579 X-Original-To: courses@linuxchix.org
5580 Delivered-To: courses@linuxchix.org
5581 Received: from localhost (localhost [127.0.0.1])
5582         by www.linuxchix.org (Postfix) with ESMTP id EE6BD273286
5583         for <courses@linuxchix.org>; Sat, 10 Dec 2005 06:48:12 +1100 (EST)
5584 Received: from www.linuxchix.org ([127.0.0.1])
5585         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
5586         id 04068-09 for <courses@linuxchix.org>;
5587         Sat, 10 Dec 2005 06:48:12 +1100 (EST)
5588 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
5589         by www.linuxchix.org (Postfix) with ESMTP id E15B5273285
5590         for <courses@linuxchix.org>; Sat, 10 Dec 2005 06:48:11 +1100 (EST)
5591 Received: from localhost (anne@localhost)
5592         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jB9JlxJ17157;
5593         Fri, 9 Dec 2005 14:47:59 -0500 (EST)
5594 Date: Fri, 9 Dec 2005 14:47:58 -0500 (EST)
5595 From: Anne G <anne@wjh.harvard.edu>
5596 To: Laurel Fan <laurel.fan@gmail.com>
5597 Subject: Re: [Courses] [Ruby] Lesson 2: Iterators
5598 In-Reply-To: <8b1e030f0512090913k7c4930f9gbfa84774d424751@mail.gmail.com>
5599 Message-ID: <Pine.SOL.4.30.0512091435410.15937-100000@wjh1.wjh.harvard.edu>
5600 MIME-Version: 1.0
5601 Content-Type: TEXT/PLAIN; charset=US-ASCII
5602 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
5603 X-Topics: Introduction to Ruby
5604 Cc: jennyw <jennyw@dangerousideas.com>, courses@linuxchix.org
5605 X-BeenThere: courses@linuxchix.org
5606 X-Mailman-Version: 2.1.5
5607 Precedence: list
5608 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
5609 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5610         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
5611 List-Archive: <http://linuxchix.org/pipermail/courses>
5612 List-Post: <mailto:courses@linuxchix.org>
5613 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
5614 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5615         <mailto:courses-request@linuxchix.org?subject=subscribe>
5616 X-List-Received-Date: Fri, 09 Dec 2005 19:48:13 -0000
5617 Content-Length: 2754
5618 Lines: 75
5622 > Without seeing all of your code, it's hard to tell what
5623 > exactly the problem is, or whether there would be a
5624 > better way to implement it without recursion.  Would you
5625 > be willing to post the whole thing to the list?
5627 Yes of course. But at this point my question is more
5628 conceptual:
5630 I changed the code so that within each block of data, I use
5631 a loop. This way, I only run getdata, getinfo1 and get info2
5632 once per subject, and so the maximum level of recursion is
5633 the number of subjects, around 200, a number which ruby can
5634 handle, and there is no error.
5636 > Each recursive method call causes a little bit of
5637 > overhead (it needs to keep track of every method
5638 > currently running), and this can add up over time.
5640 I assume that OOP can handle open ended, real time
5641 situations. So a working design would need to go back
5642 to a neutral point from time to time to clear out the
5643 methods running.
5645 In my case,
5646 getdata finds a header
5647 getdata  calls getinfo1,
5648 getinfo1 calls getinfo2
5649 getinfo2 calls getdata
5650 getdata stores the subjectdata.
5652 At this point there is a clear breaking point, and I ought
5653 to go back to neutral. Is there a ruby command which I could
5654 use to say go back to top level, forget about tracking down
5655 all those methods?
5657 anne
5658 On Fri, 9 Dec 2005, Laurel Fan wrote:
5660 > On 12/9/05, Anne G <anne@wjh.harvard.edu> wrote:
5661 > > This worked very well, getdata calls getinfo1 which calls
5662 > > getinfo2 which calls getdata ad infinitum. The problem I
5663 > > encounted is that ad infinitum is not supported by my
5664 > > implementation of Ruby, I got an error message, too many
5665 > > levels (each repeat call on getdata is a level).
5666 > >
5667 > > Of course I can find ways to write the code more efficiently
5668 > > to avoid the limit, but by calling a method for each line of
5669 > > code, I encountered a limit, and the fact that the limit
5670 > > exists is what bothers me. That means I have to make sure
5671 > > the whole program is done is so many calls.  This is not a
5672 > > stable timeless implementation. It could not run on live
5673 > > data that kept coming and coming.
5675 > Now I think I understand a bit more of what the problem is.
5677 > Recursion (methods calling themselves) might not be the best solution
5678 > for data that keeps coming continuously.  Each recursive method call
5679 > causes a little bit of overhead (it needs to keep track of every
5680 > method currently running), and this can add up over time.
5682 > It's also possible that there's a bug in the code causing an infinite
5683 > recursion loop.
5685 > Without seeing all of your code, it's hard to tell what exactly the
5686 > problem is, or whether there would be a better way to implement it
5687 > without recursion.  Would you be willing to post the whole thing to
5688 > the list?
5690 > --
5691 > Laurel Fan
5692 > http://dreadnought.gorgorg.org
5696 From anne@wjh.harvard.edu  Sat Dec 10 22:10:47 2005
5697 Return-Path: <anne@wjh.harvard.edu>
5698 X-Original-To: courses@linuxchix.org
5699 Delivered-To: courses@linuxchix.org
5700 Received: from localhost (localhost [127.0.0.1])
5701         by www.linuxchix.org (Postfix) with ESMTP id 70DDD273241
5702         for <courses@linuxchix.org>; Sat, 10 Dec 2005 22:10:47 +1100 (EST)
5703 Received: from www.linuxchix.org ([127.0.0.1])
5704         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
5705         id 10139-07 for <courses@linuxchix.org>;
5706         Sat, 10 Dec 2005 22:10:47 +1100 (EST)
5707 Received: from wjh2.wjh.harvard.edu (wjh2.wjh.harvard.edu [140.247.94.249])
5708         by www.linuxchix.org (Postfix) with ESMTP id 6AD4127323F
5709         for <courses@linuxchix.org>; Sat, 10 Dec 2005 22:10:46 +1100 (EST)
5710 Received: from localhost (anne@localhost)
5711         by wjh2.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jBABAfl15809;
5712         Sat, 10 Dec 2005 06:10:41 -0500 (EST)
5713 Date: Sat, 10 Dec 2005 06:10:41 -0500 (EST)
5714 From: Anne G <anne@wjh.harvard.edu>
5715 To: Laurel Fan <laurel.fan@gmail.com>
5716 Subject: Re: [Courses] [Ruby] Lesson 2: Iterators
5717 In-Reply-To: <8b1e030f0512090913k7c4930f9gbfa84774d424751@mail.gmail.com>
5718 Message-ID: <Pine.SOL.4.30.0512100544110.15267-100000@wjh2.wjh.harvard.edu>
5719 MIME-Version: 1.0
5720 Content-Type: TEXT/PLAIN; charset=US-ASCII
5721 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
5722 X-Topics: Introduction to Ruby
5723 Cc: courses@linuxchix.org
5724 X-BeenThere: courses@linuxchix.org
5725 X-Mailman-Version: 2.1.5
5726 Precedence: list
5727 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
5728 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5729         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
5730 List-Archive: <http://linuxchix.org/pipermail/courses>
5731 List-Post: <mailto:courses@linuxchix.org>
5732 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
5733 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5734         <mailto:courses-request@linuxchix.org?subject=subscribe>
5735 X-List-Received-Date: Sat, 10 Dec 2005 11:10:47 -0000
5736 Content-Length: 821
5737 Lines: 24
5739  > Recursion (methods calling themselves) might not be the
5740 > best solution for data that keeps coming continuously
5742 This morning I got the implications of Laurel's comment:
5743 If I want code which runs continuously, or some such, I need
5744 to make sure that the structure of the object connections
5745 does not contain a loop.
5747 In my case, I ought to be able to pass the control from
5748 object getdata to object info1 to object info2. And there it
5749 stops.
5751 If info2 does not call anyone, control gets back to getdata
5752 BY ITSELF! and it can go on with its task. getdata thus
5753 becomes the neutral state object I was talking about.
5755 In turms of diagram, it looks like an octopus, with
5756 tantacles going in different directions.
5758 Thank you so much for your help. We don't have /proc on the
5759 mac so I can't work on that part of lesson 2.
5761 anne
5764 From anne@wjh.harvard.edu  Sun Dec 18 06:45:10 2005
5765 Return-Path: <anne@wjh.harvard.edu>
5766 X-Original-To: courses@linuxchix.org
5767 Delivered-To: courses@linuxchix.org
5768 Received: from localhost (localhost [127.0.0.1])
5769         by www.linuxchix.org (Postfix) with ESMTP id 55FBE27326C
5770         for <courses@linuxchix.org>; Sun, 18 Dec 2005 06:45:10 +1100 (EST)
5771 Received: from www.linuxchix.org ([127.0.0.1])
5772         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
5773         id 05149-10 for <courses@linuxchix.org>;
5774         Sun, 18 Dec 2005 06:45:10 +1100 (EST)
5775 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
5776         by www.linuxchix.org (Postfix) with ESMTP id 3E7EB27323B
5777         for <courses@linuxchix.org>; Sun, 18 Dec 2005 06:45:08 +1100 (EST)
5778 Received: from localhost (anne@localhost)
5779         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jBHJixj29228
5780         for <courses@linuxchix.org>; Sat, 17 Dec 2005 14:45:04 -0500 (EST)
5781 Date: Sat, 17 Dec 2005 14:44:59 -0500 (EST)
5782 From: Anne G <anne@wjh.harvard.edu>
5783 To: <courses@linuxchix.org>
5784 Subject: [Courses] [Ruby] Lesson 2: Containers, Blocks, and Iterators  
5785 Message-ID: <Pine.SOL.4.30.0512171438180.28942-100000@wjh1.wjh.harvard.edu>
5786 MIME-Version: 1.0
5787 Content-Type: TEXT/PLAIN; charset=US-ASCII
5788 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
5789 X-Topics: Introduction to Ruby
5790 X-BeenThere: courses@linuxchix.org
5791 X-Mailman-Version: 2.1.5
5792 Precedence: list
5793 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
5794 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5795         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
5796 List-Archive: <http://linuxchix.org/pipermail/courses>
5797 List-Post: <mailto:courses@linuxchix.org>
5798 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
5799 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
5800         <mailto:courses-request@linuxchix.org?subject=subscribe>
5801 X-List-Received-Date: Sat, 17 Dec 2005 19:45:10 -0000
5802 Content-Length: 3480
5803 Lines: 186
5806 Questions
5807 1. write the following string declaration code?
5808 test = "thank you"
5809 test2='Laurel'
5810 test3=String.new("For")
5811 text4="y"+"o"+"u"+"r"
5814 2. What are the 4 things you can specify when calling a
5815 method?
5816 object it applies to: if not specified, applies to self.
5817 name of method
5818 arguments
5819 block
5821 * to indicate that the arguments is to be read as an array?
5822 & associated block converted to proc object?
5824 problem 1
5825 ----------
5826 # Given an array of words, findLongWords returns a new array
5827 # containing the words with more than 5 letters.
5829 def findLongWords(words)
5830   longWords = Array.new()
5831   words.each { |wrd|  longWords.push(wrd) if (wrd.length>5)
5833   return longWords
5835 p findLongWords(['thisOneIsLong', 'short', 'howAboutThisOne'
5838 solution with enumerable
5840 def findLongWords(words)
5841   words.find_all {|wrd| wrd.length>5}
5843 p findLongWords(['thisOneIsLong', 'short', 'howAboutThisOne'
5846 problem2
5847 ---------
5848 arr=%w{ dog cat aardvark bird}
5849 puts "simple sort"
5850 puts arr.sort
5851 puts "new sort"
5852 puts arr.sort_by{|wrd| (wrd.count("aeiou") + 0.01*wrd[0])}
5854 questions: yield and blocks?
5855 -----------------------------------
5856 the simple block formulation can be understood as is, but I
5857 don't really get yield, and blocks...
5859 Someone gave the following example on comp.lang.ruby
5861 class List
5862    def add(obj)
5863      @first = [@first,obj]
5864    end
5866    def each
5867      e = @first
5868      while e
5869        yield e[1]
5870        e = e[0]
5871      end
5872    end
5875 l = List.new
5876 l.add("hello")
5877 l.add("world")
5878 l.add("of")
5879 l.add("beauty")
5881 l.each do |s|
5882    puts s
5885 It puts the words in reverse order, but I don't understand
5886 why e[1] turns out to be the last word in the
5887 sequence? and why the sequence shortens each times
5888 it goes through the while loop.
5890 Since I don't understand the code, I haven't really
5891 figured out what the yield does, why it is interesting
5893 ------------------------------------------------------------
5894 Here are the other examples for those interested in yield
5895 that I would like to study next to try to get the point of
5896 yield.
5898 Example B): Traversing a data structure recursively:
5900 class Array
5901    def traverse_rec
5902      for e in self do
5903        if e.kind_of? Array
5904          e.traverse_rec
5905        else
5906          yield e
5907        end
5908      end
5909    end
5912 [ [1,2] [1,3,[4,[5] ],2,[3,4] ] ].traverse_rec do |el|
5913     puts el;
5916 outputs all elementes of the tree recursively.
5917 (The tree is implemented as an array of (possible arrays of
5918   (possible ....))... )
5920 ------------------------------------------------------------
5921 Example C)
5923 Do something with each element of the a data structure
5924 (minor variation of example 1):
5926 class List
5927    def add(obj)
5928      @first = [@first,obj]
5929    end
5931    def map
5932      e = @first
5933      while e
5934        e[1] = yield e[1]
5935      end
5936    end
5939 l = List.new
5941 l.add("hello")
5942 l.add("world")
5944 l.map do |s|
5945    s.length
5948 Each element of the list is replaced by its length.
5950 -------------------------------------------------------------
5951 Example D)
5953 Do something according to a dynamic criterion
5955 (Sum up all elements of a list conditionally)
5957 class List
5958    def add(*objs)
5959      objs.each do |obj|
5960         @first = [@first,obj]
5961      end
5962    end
5964    def sum_if
5965      e = @first
5966      sum = 0;
5967      while e
5968        sum += e[1] if yield e[1]
5969      end
5970    end
5973 l = List.new
5974 l.add(1,3,4,5,6,2,1,6);
5976 l.add_if do |i|
5977    (i%3)==0
5980 The last function sums all elements of the list which
5981 are divisible by 3.
5983 I hope it gives you some insides about the power
5984 of yield.
5985 Regards, Christian
5992 From anne@wjh.harvard.edu  Sun Dec 18 17:54:35 2005
5993 Return-Path: <anne@wjh.harvard.edu>
5994 X-Original-To: courses@linuxchix.org
5995 Delivered-To: courses@linuxchix.org
5996 Received: from localhost (localhost [127.0.0.1])
5997         by www.linuxchix.org (Postfix) with ESMTP id C1BEC273247
5998         for <courses@linuxchix.org>; Sun, 18 Dec 2005 17:54:35 +1100 (EST)
5999 Received: from www.linuxchix.org ([127.0.0.1])
6000         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
6001         id 09515-06 for <courses@linuxchix.org>;
6002         Sun, 18 Dec 2005 17:54:35 +1100 (EST)
6003 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
6004         by www.linuxchix.org (Postfix) with ESMTP id C49232731F6
6005         for <courses@linuxchix.org>; Sun, 18 Dec 2005 17:54:34 +1100 (EST)
6006 Received: from localhost (anne@localhost)
6007         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jBI6sSK28951
6008         for <courses@linuxchix.org>; Sun, 18 Dec 2005 01:54:28 -0500 (EST)
6009 Date: Sun, 18 Dec 2005 01:54:28 -0500 (EST)
6010 From: Anne G <anne@wjh.harvard.edu>
6011 To: <courses@linuxchix.org>
6012 Subject: Re: [Courses] [Ruby] Lesson 2: Containers, Blocks, and Iterators  
6013 In-Reply-To: <Pine.SOL.4.30.0512171438180.28942-100000@wjh1.wjh.harvard.edu>
6014 Message-ID: <Pine.SOL.4.30.0512180149130.28618-100000@wjh1.wjh.harvard.edu>
6015 MIME-Version: 1.0
6016 Content-Type: TEXT/PLAIN; charset=US-ASCII
6017 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
6018 X-Topics: Introduction to Ruby
6019 X-BeenThere: courses@linuxchix.org
6020 X-Mailman-Version: 2.1.5
6021 Precedence: list
6022 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
6023 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
6024         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
6025 List-Archive: <http://linuxchix.org/pipermail/courses>
6026 List-Post: <mailto:courses@linuxchix.org>
6027 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
6028 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
6029         <mailto:courses-request@linuxchix.org?subject=subscribe>
6030 X-List-Received-Date: Sun, 18 Dec 2005 06:54:36 -0000
6031 Content-Length: 1065
6032 Lines: 56
6034 I have a hard time with the book. its song example
6035 completely turns me off, it is much too wordy and too long
6036 to be of any use to me, and it keeps poping out everywhere.
6038 Here is an explanation of yield which works better for me
6040 Think of a block as an anonymous subroutine. Instead of
6041 saying
6042 def func(x,y)
6043   # ... do stuff
6045 it goes
6047 { |x,y|
6048   # ... do stuff
6052 yield is just the way you call the block passed to the
6053 function.  If you have a C/C++ background, it might help to
6054 think of blocks as function pointers and yield as
6055 dereferencing a function pointer.  Yield is similiar to a
6056 callback function.  Even closer to function pointers in
6057 C/C++ is a proc object.
6059 myproc = proc { |x,y|
6060   puts "x: #{x}, y #{y}"
6064 # You can accept these objects as parameters to functions
6065 def func(x,y,p)
6066   p.call(x,y)
6069 func(1,2,myproc)
6071 Using yield is just a more convenient way to perform the
6072 same thing.
6073 The yield version of the above might go as follows:
6075 def func(x,y)
6076   if( block_given?)
6077     yield(x,y)
6078   end
6081 func(1,2) { |x,y|
6082   puts "x: #{x}, y #{y}"
6091 From anne@wjh.harvard.edu  Wed Dec 21 19:00:18 2005
6092 Return-Path: <anne@wjh.harvard.edu>
6093 X-Original-To: courses@linuxchix.org
6094 Delivered-To: courses@linuxchix.org
6095 Received: from localhost (localhost [127.0.0.1])
6096         by www.linuxchix.org (Postfix) with ESMTP id 15055273234
6097         for <courses@linuxchix.org>; Wed, 21 Dec 2005 19:00:18 +1100 (EST)
6098 Received: from www.linuxchix.org ([127.0.0.1])
6099         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
6100         id 03495-02 for <courses@linuxchix.org>;
6101         Wed, 21 Dec 2005 19:00:17 +1100 (EST)
6102 Received: from wjh1.wjh.harvard.edu (wjh1.wjh.harvard.edu [140.247.94.230])
6103         by www.linuxchix.org (Postfix) with ESMTP id 20EFA2731BD
6104         for <courses@linuxchix.org>; Wed, 21 Dec 2005 19:00:16 +1100 (EST)
6105 Received: from localhost (anne@localhost)
6106         by wjh1.wjh.harvard.edu (8.11.7p2/8.11.6) with ESMTP id jBL806l09963
6107         for <courses@linuxchix.org>; Wed, 21 Dec 2005 03:00:09 -0500 (EST)
6108 Date: Wed, 21 Dec 2005 03:00:06 -0500 (EST)
6109 From: Anne G <anne@wjh.harvard.edu>
6110 To: <courses@linuxchix.org>
6111 Subject: [Courses] [Ruby] Lesson 2: Containers, Blocks, and Iterators  
6112 In-Reply-To: <Pine.SOL.4.30.0512171438180.28942-100000@wjh1.wjh.harvard.edu>
6113 Message-ID: <Pine.SOL.4.30.0512210248520.9573-100000@wjh1.wjh.harvard.edu>
6114 MIME-Version: 1.0
6115 Content-Type: TEXT/PLAIN; charset=US-ASCII
6116 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
6117 X-Topics: Introduction to Ruby
6118 X-BeenThere: courses@linuxchix.org
6119 X-Mailman-Version: 2.1.5
6120 Precedence: list
6121 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
6122 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
6123         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
6124 List-Archive: <http://linuxchix.org/pipermail/courses>
6125 List-Post: <mailto:courses@linuxchix.org>
6126 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
6127 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
6128         <mailto:courses-request@linuxchix.org?subject=subscribe>
6129 X-List-Received-Date: Wed, 21 Dec 2005 08:00:18 -0000
6130 Content-Length: 990
6131 Lines: 33
6133 >    def add(obj)
6134 >      @first = [@first,obj]
6135 >    end
6137 I got it. In matlab, this would append the obj to an array.
6138 Here @first is a new array, with the old @first as an
6139 element, and obj as a second element. Since this is not an
6140 array, the length method does not work.
6142 --------------------------------------------
6144 It seems that yield/block can help emphasize the goal of the
6145 transaction, and hide the mechanics to do it:  When you see
6146 a method with a puts block, you know this line is printing
6147 some info
6149 I also found it useful as a short cut when there is a
6150 process that is the same to support different actions. For
6151 example I rewrote my data reading program with blocks
6153 getinfo {|line| @info1Arr.push("'" +line[6] + "'")}
6154 increaseind
6155 getinfo {|line| @info2Arr.push(line[6])}
6156 increaseind
6157 getinfo {|line| @dataArr.push(line[0]+","+line[2]+","+line[4])}
6159 In this way the same method getinfo was used to extract
6160 different columns in the data file, depending on the block
6161 formula.
6163 anne
6167 From chantal@antenna.nl  Tue Jan  3 17:29:13 2006
6168 Return-Path: <chantal@antenna.nl>
6169 X-Original-To: courses@linuxchix.org
6170 Delivered-To: courses@linuxchix.org
6171 Received: from localhost (localhost [127.0.0.1])
6172         by www.linuxchix.org (Postfix) with ESMTP id 984CD27323E
6173         for <courses@linuxchix.org>; Tue,  3 Jan 2006 17:29:13 +1100 (EST)
6174 Received: from www.linuxchix.org ([127.0.0.1])
6175         by localhost (nest [127.0.0.1]) (amavisd-new, port 10024) with SMTP
6176         id 07252-07 for <courses@linuxchix.org>;
6177         Tue, 3 Jan 2006 17:29:13 +1100 (EST)
6178 X-Greylist: delayed 627 seconds by postgrey-1.21 at nest;
6179         Tue, 03 Jan 2006 17:29:12 EST
6180 Received: from www6.antenna.nl (www6.antenna.nl [194.255.18.15])
6181         by www.linuxchix.org (Postfix) with ESMTP id A912C273225
6182         for <courses@linuxchix.org>; Tue,  3 Jan 2006 17:29:12 +1100 (EST)
6183 Received: from www6.antenna.nl (localhost [127.0.0.1])
6184         by www6.antenna.nl (8.12.6/8.12.6/SuSE Linux 0.6) with ESMTP id
6185         k036IQh8023186; Tue, 3 Jan 2006 07:18:31 +0100
6186 Received: (from nobody@localhost)
6187         by www6.antenna.nl (8.12.6/8.12.6/Submit) id k036IQUd023185;
6188         Tue, 3 Jan 2006 07:18:26 +0100
6189 X-Authentication-Warning: www6.antenna.nl: nobody set sender to
6190         chantal@antenna.nl using -f
6191 Received: from ip3e8305c6.speed.planet.nl (ip3e8305c6.speed.planet.nl
6192         [62.131.5.198]) by webmail.antenna.nl (IMP) with HTTP 
6193         for <chantal@www6.antenna.nl>; Tue,  3 Jan 2006 07:18:25 +0100
6194 Message-ID: <1136269105.43ba17317ff34@webmail.antenna.nl>
6195 Date: Tue,  3 Jan 2006 07:18:25 +0100
6196 From: chantal@antenna.nl
6197 To: laurel.fan@gmail.com
6198 Subject: Re: [Courses] [Ruby] Lesson 0: Installing, References,
6199         and your first homework assignment]
6200 MIME-Version: 1.0
6201 Content-Type: text/plain; charset=ISO-8859-1
6202 User-Agent: Internet Messaging Program (IMP) 3.2.4
6203 X-Originating-IP: 62.131.5.198
6204 Content-Transfer-Encoding: quoted-printable
6205 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at linuxchix.org
6206 X-Topics: Introduction to Ruby
6207 Cc: courses@linuxchix.org
6208 X-BeenThere: courses@linuxchix.org
6209 X-Mailman-Version: 2.1.5
6210 Precedence: list
6211 List-Id: List for courses run by LinuxChix volunteers <courses.linuxchix.org>
6212 List-Unsubscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
6213         <mailto:courses-request@linuxchix.org?subject=unsubscribe>
6214 List-Archive: <http://linuxchix.org/pipermail/courses>
6215 List-Post: <mailto:courses@linuxchix.org>
6216 List-Help: <mailto:courses-request@linuxchix.org?subject=help>
6217 List-Subscribe: <http://mailman.linuxchix.org/mailman/listinfo/courses>,
6218         <mailto:courses-request@linuxchix.org?subject=subscribe>
6219 X-List-Received-Date: Tue, 03 Jan 2006 06:29:13 -0000
6220 Content-Length: 1905
6221 Lines: 53
6223 Hi Laurel, sorry for the late reply, here's what I have so far, I started=
6224  on the
6225 bonus question but it's not finished yet :-)
6227 1. Defining classes: photo gallery. Think about what classes you
6228 would need to define to write a web photo gallery application. For
6229 now, don't think of the actual implementation details of handling
6230 web requests, displaying images, etc. Obviously you'll need to
6231 represent a photo. What attributes does it have? What other
6232 objects do you need?
6233 post what you have done)
6235 attributes of a photo are:
6237 - width
6238 - height
6239 - filename
6240 - subject
6241 - date
6243 2. Defining classes: /proc. (This might not be as interesting for
6244 windows users). On unix, the /proc filesystem is a virtual
6245 filesystem containing information about the running processes
6246 (among other things). It contains a directory for each running
6247 process, which contains information about the process, such as the
6248 command line, the amount of memory it's using, etc). <A0>Define a set
6249 of classes to represent the process data in /proc.
6251 every file in the process directories could be considered a class, althou=
6252 gh I
6253 don't really know what they all mean.
6254 I will pick a few of them to use in the exercise:
6256 - status, I guess the attributes are everything that is listed in the fil=
6258 /proc/$processid/status
6259 - cmdline, its attribute is the (current?) init level
6260 - statm,  The status of the memory in use by the process, its attributes:
6261          Total program size, in kilobytes.
6262          Size of memory portions, in kilobytes.
6263          Number of pages that are shared.
6264          Number of pages that are code.
6265          Number of pages of data/stack.
6266          Number of library pages.
6267          Number of dirty pages.
6268 (I found some info about the proc dir here:
6269 http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/ref-guide/s1-=
6270 proc-di
6271 rectories.html)
6273 Chantal
6275 ----------------------------------------------------------------