[Instantrails-users] REXML question

Gavin Sinclair gsinclair at gmail.com
Sat Apr 29 19:56:14 EDT 2006

On 4/30/06, Bill Walton <bill.walton at charter.net> wrote:
> >
> > Did the tutorial even mention irb?  That's a normal
> > side effect of irb. Since it is interactive, it gives you
> > lots of output.   A normal program run from a file
> > won't have any of that output.
> No, it didn't actually.  I guess I inferred that from the box in the article
> titled "Accessing Elements".  It lookes like command line input / output.
> The tutorial's at
> http://www.germane-software.com/software/rexml/docs/tutorial.html  in case
> you want to see.  I thought maybe he was using a *nix box or something.
> Just a good lesson for me, I guess, re: how to write a tutorial that
> confuses an audience of newbies ;-)

Don't worry, Bill.  Once you've worked through this tutorial and
gained some more experience with how Ruby and IRB work, things like
this won't trouble you anymore.  What Sean has done in the tutorial is
use a normal Ruby convention for displaying the (expected) output of
various lines of code.  That is:

   # -> output


   code        # -> output

Many people use => instead of ->, but I prefer the latter, and so does
Sean, apparently.

When showing the expected output, one wants to be brief.  You don't
show the output for every single line of code (the doc = Document.new
file output wasn't given because it's part of "uninteresting" setup
code) and you abbreviate the output just to get the point across. 
Showing a whole IRB transcript would have helped you but it's too
verbose for the purpose of the tutorial.

The moral of the story?  If you think you've hit a snag, investigate. 
Copy the following function into your IRB session (or IRB
configuration file -- is it $HOME/_irbrc?):

  def hlp(obj=nil)    # Note: not "help" which is an IRB reserved word
(I think).
    if obj
      puts (obj.methods - Object.new.methods).sort
      puts obj.methods.sort

Then, if you don't know what an object is (like "doc"),

   hlp doc

will list all of doc's methods, except the trivial ones.

The following can also be useful:

   require 'yaml'
   puts doc.to_yaml

Google "irb tips and tricks" for more.


More information about the Instantrails-users mailing list