Ruby / rails newbie - Finding documentation in RDocs

(steveH) #1

Hi, I'm brand new to ruby, to which I've been attracted by rails (along
with many others, no doubt). I'm trying to hack together my first rxml
template, but my first dip into the rdocs is a total failure. I see
code like this...

  <% for column in Product.content_columns %>
    <th><%= column.human_name %></th>
  <% end %>

but I can't find a description of class Column anywhere - can't see it
in rails docs, core ruby docs, MySQL/Ruby docs - have I just missed it
or is it somewhere else, or isn't it a class at all but some sort of
dynamic ruby magic which I've totally misunderstood...

thanks for any help

(James Britt) #2

steveH wrote:

Hi, I'm brand new to ruby, to which I've been attracted by rails (along
with many others, no doubt). I'm trying to hack together my first rxml
template, but my first dip into the rdocs is a total failure. I see
code like this...

  <% for column in Product.content_columns %>
    <th><%= column.human_name %></th>
  <% end %>

but I can't find a description of class Column anywhere - can't see it
in rails docs, core ruby docs, MySQL/Ruby docs - have I just missed it
or is it somewhere else, or isn't it a class at all but some sort of
dynamic ruby magic which I've totally misunderstood...

In the construct

   for x in some.collection
     ...
   end

x is a variable that takes on the file of each successive item in collection.

See

http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_containers.html

and, in general,

http://www.ruby-doc.org/docs/ProgrammingRuby/
http://www.ruby-doc.org/gettingstarted/

James

···

--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys

(Dave Burt) #3

James Britt offered:

steveH wrote:

  <% for column in Product.content_columns %>
    <th><%= column.human_name %></th>
  <% end %>

but I can't find a description of class Column anywhere - can't see it
in rails docs, core ruby docs, MySQL/Ruby docs - have I just missed it
or is it somewhere else, or isn't it a class at all but some sort of
dynamic ruby magic which I've totally misunderstood...

In the construct

  for x in some.collection
    ...
  end

x is a variable that takes on the file of each successive item in
collection.

See [...]

James is right, there is no explicit type or class set for column, or indeed
any Ruby variable. All Ruby variables have the dynamic ruby magic property
of being able to hold an object of any type.

Here's some trivia realted to your question, though. For most or all of the
connection adapters, content_columns will return an Array of Column, a.k.a.
ActiveRecord::ConnectionAdapters::Column, which is a class in Rails, but
doesn't appear in the API docs. It has properties: name, default, type and
limit. You can read the source code for ConnectionAdapters, the
AbstractAdapter, and the adapter for your database if you want to know more.

Cheers,
Dave