<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>ClearNet Security: Tag Rails</title>
    <link>http://blog.clearnetsec.com/articles/tag/rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Rubies, Rubies, Ruby</title>
      <description>&lt;p&gt;
&lt;img src="http://www.clearnetsec.com/roller/resources/cns/2501.jpg"&gt;
&lt;p&gt;So what is the furor over the Ruby programming language lately?  I have known about Ruby for a few years but never got into it much until recently.  I had always heard of it in context of Python vs. Ruby on the Python programming list usually with the Python guys bashing Ruby over this our that.  So what is it that is making Ruby so popular now?&lt;/p&gt;

&lt;img src="http://www.clearnetsec.com/roller/resources/cns/2502.jpg" align="right"&gt;
&lt;p&gt;Now Ruby on Rails is a framework that helps you create a web application that can render dynamic content quickly and easily.  What the hell does that mean?  It basically means that Ruby on Rails has a lot of code and functionality ALREADY built for you to use.  In a matter of minutes (after installing all the stuff of course!) you can have a web page that queries your database and displays the data.&lt;/p&gt;

&lt;p&gt;So what does this have to do with Ruby exactly?  Well Ruby enables Rails to be so simple and easy to use.  So by now you are thinking what is it that makes Ruby the language so good&#8230;  The official list most people will say is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is object-oriented down to its toe nails&lt;/li&gt;
&lt;li&gt;Simple syntax, not too many non-alphanumeric in use&lt;/li&gt;
&lt;li&gt;It is interpreted, making prototyping fast&lt;/li&gt;
&lt;li&gt;It is cool as of March 6th, 2006&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So what?  Python (or insert other language) is Object oriented, simple, and interpreted.  Well I will list some of MY items that make me want to continue to master Ruby.&lt;/p&gt;

&lt;p&gt;First off the ability of an object to know all its methods is great.  In many languages you have to pass a value to a function (I know sounds technical!?) to get that value to do something. A method is basically all the functions an object can execute and a function is a stand alone operation that is not associated with an object.  The way this manifests is in the way you call each.  A method is called like object.method and a function is function(value).  An example would be making a string into a number:&lt;/p&gt;
&lt;p&gt;The Python function:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;x = "11" &lt;-- This is a string because of the double quotes.&lt;/li&gt;
&lt;li&gt;int(x) &lt;-- We call a function called int() to make "11" in 11.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Ruby method:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;x = "11" &lt;-- Again this is a string saved to x.&lt;/li&gt;
&lt;li&gt;x.to_i &lt;-- The string object x has a method to convert a string to integer this case 11.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python of course has many objects and methods itself and the langauage is actually really cool too, it is just that I like Ruby that much more.&lt;/p&gt;

&lt;p&gt;Second is the use of block code and iterators in Ruby instead of using the stereotypically looping constructs.  This is great as you can essential build smarter &#8220;loops&#8221; as the objects themselves know how to iterate over themselves instead of you knowing (or learning) how to iterate over them. For example how you would iterate over a string is different than an array or hash right?  How would you iterate over a custom object you create?  In ruby it is simple to iterate over an object like so:&lt;/p&gt;
&lt;p&gt;Ruby iteration:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;x =  [1,2,3] &lt;-- this is now an array (one object) of three things, 1, 2, and 3.&lt;/li&gt;
&lt;li&gt;x.each {|i| puts i} &lt;-- This is a loop basically a for loop!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now what happened there and what is all that stuff?  Well first off x.each is a method call for the object x which happens to be an array.  The each method will return each item in an array one by one.  Then each will pass the item to the block which is everything between the {}.  The block will put the item into the variable i then execute the statement "puts i" which prints the value to the screen.  This will be done for each item passed to it by the objects &#8220;each&#8221; method.  Sounds hard but it is easier than this:&lt;/p&gt;

&lt;p&gt;A Java for loop:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;for ( i=1; i&lt;6; i++ ) { &lt;-- This will assign 1 to i and only run the loop if i is less than 6. Also i is added to each iteration.  How do I know this from looking at it?  I don't, a book told me.&lt;br&gt;
System.out.println(i); } &lt;--Prints what is stored in i.&lt;/li&gt;
&lt;/ul&gt;

&lt;img src="http://www.clearnetsec.com/roller/resources/cns/2504.jpg"&gt;

&lt;p&gt;Third, Ruby has CPAN like functionality.  I don't mean that Ruby is watching the White House press room for late breaking info.  What I mean is that Ruby has similar functionality to the Perl Comprehensive Archive Network.  Well CPAN is where you go if you are a Perl programmer that needs ready made code for something like SSHing, parsing XML etc.

&lt;img src="http://www.clearnetsec.com/roller/resources/cns/2503.jpg" align="right"&gt;

  Odds are that someone has done that task and placed it on the web.  CPAN allows perl programmers to easily retrieve and install these modules of code and use them.  So what is the Ruby equivalent?  It is called Ruby Gems.  Gems is no where as Comprehensive as Perl yet, cause Perl is as old as the Rocky Mountains but it has lots of functionality already.  The gem program is how you get rails installed onto your system.&lt;/p&gt;

&lt;p&gt;So you want Rails to go with your ruby ring?  Step into my gem room and we will see what we can do:&lt;/p&gt;

&lt;p&gt;
Red ~ # gem install rails&lt;br&gt;
Attempting local installation of 'rails'&lt;br&gt;
Local gem file not found: rails*.gem&lt;br&gt;
Attempting remote installation of 'rails'&lt;br&gt;
Updating Gem source index for: http://gems.rubyforge.org&lt;br&gt;
Install required dependency rake? [Yn]  &lt;em&gt;y&lt;/em&gt;&lt;br&gt;
Install required dependency activesupport? [Yn] &lt;em&gt;y&lt;/em&gt;&lt;br&gt;
Install required dependency activerecord? [Yn]  &lt;em&gt;y&lt;/em&gt;&lt;br&gt;
Install required dependency actionpack? [Yn]  &lt;em&gt;y&lt;/em&gt;&lt;br&gt;
Install required dependency actionmailer? [Yn]  &lt;em&gt;y&lt;/em&gt;&lt;br&gt;
Install required dependency actionwebservice? [Yn]  &lt;em&gt;y&lt;/em&gt;&lt;br&gt;
Successfully installed rails-1.0.0&lt;br&gt;
Successfully installed rake-0.7.0&lt;br&gt;
Successfully installed activesupport-1.2.5&lt;br&gt;
Successfully installed activerecord-1.13.2&lt;br&gt;
Successfully installed actionpack-1.11.2&lt;br&gt;
Successfully installed actionmailer-1.1.5&lt;br&gt;
Successfully installed actionwebservice-1.0.0&lt;br&gt;
Installing RDoc documentation for rake-0.7.0...&lt;br&gt;
Installing RDoc documentation for activesupport-1.2.5...&lt;br&gt;
Installing RDoc documentation for activerecord-1.13.2...&lt;br&gt;
Installing RDoc documentation for actionpack-1.11.2...&lt;br&gt;
Installing RDoc documentation for actionmailer-1.1.5...&lt;br&gt;
Installing RDoc documentation for actionwebservice-1.0.0...&lt;br&gt;
Red ~ # &lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Hmm well I will let you guys off for now with this thought.  Most times I find that I struggle with the language more than I struggle with the problem I am trying to solve.  Ruby has helped me with this one issue.  Doh!!! Now I have no excuse for not solving my issues...&lt;/p&gt;

</description>
      <pubDate>Fri, 10 Mar 2006 21:08:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:0821f439-c909-42a9-b2e1-68dd33f41d7f</guid>
      <author>Cory Stoker</author>
      <link>http://blog.clearnetsec.com/articles/2006/03/10/rubies-rubies-ruby</link>
      <category>Ruby</category>
      <category>Ruby on Rails</category>
      <category>Rails</category>
      <category>Cory Stoker</category>
      <category>ClearNet Security</category>
      <category>Python</category>
    </item>
  </channel>
</rss>
