From: Paul van Delst Date: 2006-08-04T04:55:12+09:00 Subject: Re: I’m having a hard time learning ruby. Nate Imaqaguy wrote: > For starters, just do you know where I’m coming from: I have little to > no programming experience, except for some C and VB classes I took 6 > years ago, which I did fine in. > > My biggest hurdle getting started with ruby is finding which > methods/classes/files to call upon for whatever the heck I’m trying to > accomplish. > > I’m use to being able to perform a search, like in MSDN Library, using > key words of something I’m trying to perform. Then research results > from there, and get pointed in the right direction (with explanations on > what the feature does, and examples, etc). > > The editors also helped with showing the available methods, as I wrote > the code. > > So, with ruby, I’m using the SciTE editor (on WinXP), which doesn’t give > method options as you go. Yeah, I know they are kinda like training > wheels, but they help when you’re starting out. > > And I can’t really find any close equivalent to using something like an > MSDN Library. The best thing someone has pointed me to so far is > http://www.ruby-doc.org/. Which is cool and all, but it’s not really > “searchable”—you kind of have to know what file/class/method to look up > in the first place. And even if I find what I think I’m looking for, > the documentation is confusing to me. Sometimes there isn’t the > slightest word as to what something does. Oh man, you have just described my recent experiences to a T. Although it's not searchable, the on-line version of the Programming Ruby "pickaxe" book, http://www.rubycentral.com/book does do a pretty good job of listing just about everything built in on one page: http://www.rubycentral.com/book/builtins.html After reading the paper version of the Pickaxe book, I bought a PDF version (only 10 bucks) of the Pickaxe (see http://www.pragmaticprogrammer.com) and keep it open on my desktop - along with the builtin library page above, and the Ruby-doc.org page you mentioned. I'm still in the hunting and gathering stage of ruby coding, but having those three resources available -- along with Google -- as I'm editing ruby code has been invaluable. In addition there are quite a number of webpages out there containing teaching examples and code snippets. Oh, and the Ruby Cookbook is a must have too (although it's a hefty beast at 900-odd pages...and it doesn't look like it will be released as a PDF book anytime soon.) > Someone told me about “.methods”, but that only works if you’re in an > irb session, which I find painful to use because I have to type all my > code in, line by line. I can’t even figure out how to paste each line > of the code I already have. Inevitably I fat finger something and get > mad. I hear ya. On my Mac laptop, I haven't figured out how to get command line recall+traverse (up/down,left/right arrows) yet in irb. Drives me nuts. But you can play around within a regular source file rather than use irb directly. Sometimes I just play around at the end of a source file, e.g. -------- in file fruit.rb --------- #!/usr/bin/env ruby class Fruit def initialize @bananas=0 end def pick @bananas += 1 end def eat @bananas -= 1 end def howmany? @bananas end end # Muck around test code for above classes follows..... fruit=Fruit.new puts "Picking some fruit...." (1..10).each {|i| fruit.pick} puts "Eating some fruit...." fruit.eat puts "I have #{fruit.howmany?} piece(s) of fruit left." --------------------------------- And then simply do $ ruby -w fruit.rb on the command line or, in irb, use "require" irb(main):001:0> require 'fruit' Picking some fruit.... Eating some fruit.... I have 9 piece(s) of fruit left. => true to see if the stuff after the "actual" code (e.g. classes, modules, whatnot) does what I think it does. If not, I modify, save, and re-run. Extremely low-tech .... but I'm having a ball. :o) cheers, paulv -- Paul van Delst Ride lots. CIMSS @ NOAA/NCEP/EMC Eddy Merckx Ph: (301)763-8000 x7748 Fax:(301)763-8545