<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Easy Ruby On Rails Programming &#187; Sample Code</title>
	<atom:link href="http://easyrubyonrailsprogramming.com/tag/sample-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://easyrubyonrailsprogramming.com</link>
	<description>The Place to be to Learn Ruby On Rails</description>
	<lastBuildDate>Tue, 10 Aug 2010 10:07:05 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simplifying the code</title>
		<link>http://easyrubyonrailsprogramming.com/development/simplifying-the-code/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/simplifying-the-code/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 10:07:05 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[Simplifying code]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/uncategorized/simplifying-the-code/</guid>
		<description><![CDATA[
We now check if the book titles are deleted from the first and end of the list which should give us &#8216;nil&#8217; when and if the list becomes void of contents.
list.deleteFirst 	>> Books: ABDC&#8211;Author1 (1)
list.deleteFirst	>> Books: EFGH&#8211;Author2 (2)
list.deleteLast	>> Books: MNOP&#8211;Author1 (1)
list.deleteLast	>> Books: IJKL&#8211;Author3 (3)
list.deleteLast	>> nil
We now include the use of the square brackets which allows [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.statomatic.com/features3.htm"><img src="/wp-content/uploads/scraped/20.jpg"/></a>
<p>We now check if the book titles are deleted from the first and end of the list which should give us &#8216;nil&#8217; when and if the list becomes void of contents.</p>
<p>list.deleteFirst 	>> Books: ABDC&#8211;Author1 (1)<br />
list.deleteFirst	>> Books: EFGH&#8211;Author2 (2)<br />
list.deleteLast	>> Books: MNOP&#8211;Author1 (1)<br />
list.deleteLast	>> Books: IJKL&#8211;Author3 (3)<br />
list.deleteLast	>> nil</p>
<p>We now include the use of the square brackets which allows us to acces the specific elements by the index instead of having to define each item specifically.</p>
<p>class BookList<br />
	def[](key)<br />
		if key.kind_of?(Integer)<br />
			@Books[key]<br />
		else<br />
			# &#8230;<br />
		end<br />
	end<br />
end</p>
<p>Testing the code is also very straightforward:</p>
<p>list[0]		>> Books: ABCD &#8212; Author1 (1)<br />
list[2]		>> Books: IJKL &#8212; Author  (3)<br />
list[9]		>> nil	</p>
<p>The next posts will add more functions and operators to further simplify our code making it shorter and making you more familiar with the syntax of Ruby.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/simplifying-the-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Append</title>
		<link>http://easyrubyonrailsprogramming.com/development/append/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/append/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 10:02:53 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sample Code]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/append/</guid>
		<description><![CDATA[
Using the append command/method, we can add an element to the end of the table which in turn returns a reference to the current BookList object.The deleteFirst and deleteLast command allows us to delete the first and last records respectively in the following form/s:
For Append:
class BookList
	def append(aBook)
		@books.push(aBook)
		self
	end
end
For deleteFirst and deleteLast
class BookList
	def deleteFirts
		@books.shift
	end
	def deleteLast
		@books.pop
	end
end
Now we test [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.main.nc.us/openstudio/tinamanley/Iraq/append.htm"><img src="/wp-content/uploads/scraped/19.jpg"/></a>
<p>Using the append command/method, we can add an element to the end of the table which in turn returns a reference to the current BookList object.The deleteFirst and deleteLast command allows us to delete the first and last records respectively in the following form/s:</p>
<p>For Append:<br />
class BookList<br />
	def append(aBook)<br />
		@books.push(aBook)<br />
		self<br />
	end<br />
end</p>
<p>For deleteFirst and deleteLast</p>
<p>class BookList<br />
	def deleteFirts<br />
		@books.shift<br />
	end<br />
	def deleteLast<br />
		@books.pop<br />
	end<br />
end</p>
<p>Now we test the code we have just created to show if the right operations are being performed and if we are getting the results we desire:</p>
<p>list = BookList.new<br />
list.<br />
	append(Books.new(&#8216;ABCD&#8217;, &#8216;Author1&#8242;,1)).<br />
	append(Books.new(&#8216;EFGH&#8217;, &#8216;Author2&#8242;,2)).<br />
	append(Books.new(&#8216;IJKL&#8217;, &#8216;Author3&#8242;,3)).<br />
	append(Books.new(&#8216;MNOP&#8217;, &#8216;Author4&#8242;,4))</p>
<p>In the next posts, we get to check and simplify the code we have just executed.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/append/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks &#8211; Example</title>
		<link>http://easyrubyonrailsprogramming.com/development/blocks-example/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/blocks-example/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 12:16:09 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[Sample Code]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/blocks-example/</guid>
		<description><![CDATA[
Below, we find sample code which uses block to return the values of the Fibonacci number Series.
def fibMax(max)
     a1, a2 =1,1 # variables that are assigned parallel values
     while a1 ]]></description>
			<content:encoded><![CDATA[<p><a href="http://bobspaintshop.com/gpage5.html"><img src="/wp-content/uploads/scraped/25.jpg"/></a>
<p>Below, we find sample code which uses block to return the values of the Fibonacci number Series.</p>
<p>def fibMax(max)<br />
     a1, a2 =1,1 # variables that are assigned parallel values<br />
     while a1 <= max<br />
	yield a1<br />
	a1, a2 = a2, a1+a2<br />
     end<br />
end<br />
fibMax(1000) {|f| print f, &#8221; &#8220;}</p>
<p>The above code gives us the value of the Fibonacci series numbers till the number 1000 which is the set maximum number to reach.</p>
<p>Sample Code Output:<br />
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987</p>
<p>The above example shows how the block(chunk of code) processed the Fibonacci Series of numbers, returning only those that fell within the set limit of 1000.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/blocks-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Container Creation</title>
		<link>http://easyrubyonrailsprogramming.com/development/18/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/18/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 10:00:59 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sample Code]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/18/</guid>
		<description><![CDATA[
To initialize a container we will do the same steps showing code to support the things that have to be done. We create a table where we can add elements to the contents delete objects from either the beginning or the last entries and display an entry using the index or content on the index. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://livedocs.adobe.com/flex/3/html/layoutperformance_03.html"><img src="/wp-content/uploads/scraped/18.jpg"/></a>
<p>To initialize a container we will do the same steps showing code to support the things that have to be done. We create a table where we can add elements to the contents delete objects from either the beginning or the last entries and display an entry using the index or content on the index. We initialize/create the array with the following syntax:</p>
<p>class BookList<br />
     def initialize<br />
	@books = Array.new<br />
     end<br />
end</p>
<p>We now have a table of book titles to which to add, delete and move data from. In the next post we will use the ‘append’ command to input data into the container we have just created.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/18/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
