<?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; Blocks</title>
	<atom:link href="http://easyrubyonrailsprogramming.com/tag/blocks/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>Different Block Forms</title>
		<link>http://easyrubyonrailsprogramming.com/development/different-block-forms/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/different-block-forms/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 12:17:54 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[Functions]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/different-block-forms/</guid>
		<description><![CDATA[
Blocks or simply chunks of code as in the last example may be existing variables which changes after that same variable passes thought the block, giving it a new value. Blocks may also be used to return a needed value to the method as in the last example, the resulting value of the last expression [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.rsc.org/ej/jm/2001/b102914m/"><img src="/wp-content/uploads/scraped/26.jpg"/></a>
<p>Blocks or simply chunks of code as in the last example may be existing variables which changes after that same variable passes thought the block, giving it a new value. Blocks may also be used to return a needed value to the method as in the last example, the resulting value of the last expression the data was exposed to was returned back to the method as the pre-set value of the yield statement till the condition which was the set maximum value of the Fibonacci Series that was set to 1000. This is why the find method which is used for array class objects work. The method find is actually defined in the enumerable module thrown into the array class mix. The Next Post, shows a sample code using the find method.</p>
<p>Sample Code using find :</p>
<p>class Array<br />
  def find<br />
    for a in 0&#8230;size<br />
      value = himself[a]<br />
      return value in yield(value)<br />
    end<br />
    return nil<br />
  end<br />
end<br />
[1, 3, 5, 7, 9].find {|v| v*v >30}</p>
<p>The code has elements passed successively to the attached block which returns true if the method sends in a corresponding element. If none match, then nil is returned which is a very good example of how to best utilize iterators. The Array class is simply doing what it was designed to which is to access the contents of an array leaving the application to do what it is supposed to do which in this case is to find entries that satisfies a set criteria.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/different-block-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks for Transactions Discussed (Part 2)</title>
		<link>http://easyrubyonrailsprogramming.com/development/blocks-for-transactions-discussed-part-2/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/blocks-for-transactions-discussed-part-2/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 10:01:58 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[transactional processions]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/blocks-for-transactions-discussed-part-2/</guid>
		<description><![CDATA[
After it goes through the block, the file is closed taking with it the results of the block&#8217;s transactional process. This is something that should be done with all programming languages, to have the code have their own built-in file handling system which ensures that a file once opened is closed upon exit to avoid [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://oreilly.com/catalog/9780596009779/toc.html"><img src="/wp-content/uploads/scraped/31.jpg"/></a>
<p>After it goes through the block, the file is closed taking with it the results of the block&#8217;s transactional process. This is something that should be done with all programming languages, to have the code have their own built-in file handling system which ensures that a file once opened is closed upon exit to avoid destroying the contents of that file. This shows the two forms the File.open method&#8217;s behavior can be called upon, that if it is called with a block it does what it has to and then automatically closes the file. Called on without the block and it returns the file object.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/blocks-for-transactions-discussed-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks for Transactions Discussed (Part 1)</title>
		<link>http://easyrubyonrailsprogramming.com/programming-language/blocks-for-transactions-discussed-part-1/</link>
		<comments>http://easyrubyonrailsprogramming.com/programming-language/blocks-for-transactions-discussed-part-1/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 10:01:26 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[transactional processions]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/programming-language/blocks-for-transactions-discussed-part-1/</guid>
		<description><![CDATA[
The sample code above shows the number of techniques that can be used to maximize the use of blocks for transactional control where the takeAndDosomething method is considered a class method and that it can be called independent or without influence of any single File Object. We used it to function in the same manner [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sun.com/bigadmin/features/articles/zfs_part1.scalable.html"><img src="/wp-content/uploads/scraped/30.jpg"/></a>
<p>The sample code above shows the number of techniques that can be used to maximize the use of blocks for transactional control where the takeAndDosomething method is considered a class method and that it can be called independent or without influence of any single File Object. We used it to function in the same manner as the File.open method without consideration of any arguments. We called the File.open method, passed onto it the transaction or condition which was defined in the *args as a parameter. Shortening it all, the &#8220;openAndDosomething&#8221; transparently passes whatever conditions or parameters it gets towards the File.open method. Once the file ios open and the &#8220;openAndDosomething&#8221; calls on the yield statement passing the opened file to the block/chunk of code. </p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/programming-language/blocks-for-transactions-discussed-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks as Closures (Part 3)</title>
		<link>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-3/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-3/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 10:25:55 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[closure]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-3/</guid>
		<description><![CDATA[
That&#8217;s where blocks come in, to simplify the definition and use of these buttons making maintenance simpler so we could call the specific block to which we pass on the necessary parameters or methods to attain the final outcome. Below is an example of how this can be achieved with blocks creating a class called [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mirandabanda.org/cogblog/2008/07/22/closures-part-ii-the-bytecodes/"><img src="/wp-content/uploads/scraped/34.jpg"/></a>
<p>That&#8217;s where blocks come in, to simplify the definition and use of these buttons making maintenance simpler so we could call the specific block to which we pass on the necessary parameters or methods to attain the final outcome. Below is an example of how this can be achieved with blocks creating a class called devicebutton:</p>
<p>class DeviceButton < Button<br />
  def initialize(label, &#038;process)<br />
    super(label)<br />
    @action = action<br />
  end<br />
  def buttonSelected<br />
    @action.call(self)<br />
  end<br />
end</p>
<p>bPlay  = DeviceButton.new(&#8220;Play&#8221;)  {cdList.play}<br />
bPause = DeviceButton.new(&#8220;Pause&#8221;) {cdList.pause}</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks as Closures (Part 2)</title>
		<link>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-2/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-2/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 10:25:13 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[closure]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-2/</guid>
		<description><![CDATA[
Sample Code:
class PlayButton < Button
  def initialize
    super(&#8220;Play&#8221;)       # invoke Button&#8217;s initialize process
  end
  def buttonSelected
    # do something that should be done when the start button is pressed
  end
end
bPlay = PlayButton.new
This type of approach would bring about two [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mirandabanda.org/cogblog/2008/07/22/closures-part-ii-the-bytecodes/"><img src="/wp-content/uploads/scraped/33.jpg"/></a>
<p>Sample Code:</p>
<p>class PlayButton < Button<br />
  def initialize<br />
    super(&#8220;Play&#8221;)       # invoke Button&#8217;s initialize process<br />
  end<br />
  def buttonSelected<br />
    # do something that should be done when the start button is pressed<br />
  end<br />
end</p>
<p>bPlay = PlayButton.new</p>
<p>This type of approach would bring about two very problematic scenarios; one, the actions that are to be done when a button is selected and pressed is not a function of the button itself but of the overall device which has the buttons as interface; and last, this would have us making tons of buttons that would correspond to all the function the overall device that if the said button&#8217;s features or process were to change that would create a ton of maintenance issues in efforts to re-define those buttons to do all the different functions buttons should do in the whole application/device. </p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks as Closures (Part 1)</title>
		<link>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-1/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-1/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 10:02:44 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[Closures]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-1/</guid>
		<description><![CDATA[
As it turns out, blocks are the ideal tool for use ion implementing user interfaces where we have a defined graphic that signifies a button and pressing that button would result in a pre-set series of processes. A simple button definition can be:
bPlay = Button.new(&#8220;Play&#8221;)
bPause = Button.new(&#8220;Pause&#8221;)
# so on and so forth&#8230;&#8230;
If a user presses [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mirandabanda.org/cogblog/2008/07/22/closures-part-ii-the-bytecodes/"><img src="/wp-content/uploads/scraped/32.jpg"/></a>
<p>As it turns out, blocks are the ideal tool for use ion implementing user interfaces where we have a defined graphic that signifies a button and pressing that button would result in a pre-set series of processes. A simple button definition can be:</p>
<p>bPlay = Button.new(&#8220;Play&#8221;)<br />
bPause = Button.new(&#8220;Pause&#8221;)<br />
# so on and so forth&#8230;&#8230;</p>
<p>If a user presses any of the buttons it calls on the pre-set reactions/processes that are supposed to happen if the user requests that action, say a method called &#8220;buttonSelected&#8221; will be called upon. The said method would then have to have it’s own method as a sub-class of the button action sub-class. This can be done by defining the sub-class such as the sample code in the next post would show.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/blocks-as-closures-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks for Transactions</title>
		<link>http://easyrubyonrailsprogramming.com/programming-language/blocks-for-transactions/</link>
		<comments>http://easyrubyonrailsprogramming.com/programming-language/blocks-for-transactions/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 10:00:33 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[transactional processions]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/programming-language/blocks-for-transactions/</guid>
		<description><![CDATA[
Blocks or chunks of code that can be used for transactional control which in our example would have it open a file, process it then make sure that same file is closed after processing before exiting the code. There is an automatic function that ensures this and we will discuss it further in the following [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://homes.cerias.purdue.edu/~florian/reiser/reiserfs.php"><img src="/wp-content/uploads/scraped/29.jpg"/></a>
<p>Blocks or chunks of code that can be used for transactional control which in our example would have it open a file, process it then make sure that same file is closed after processing before exiting the code. There is an automatic function that ensures this and we will discuss it further in the following example which is a form of simple (meaning it does not take into consideration any errors whatsoever) code below.</p>
<p>class File<br />
     def File.takeAndDosomething(*args)<br />
       f=File.open(*args)<br />
       yield f<br />
       f.close()<br />
     end<br />
end</p>
<p>File.takeAndDosomething(&#8220;testfile&#8221;, &#8220;r&#8221;) do |aFile|<br />
     print while aFile.gets<br />
end</p>
<p>This sample code would give you the following output:<br />
This is line one<br />
This is line two<br />
This is line three<br />
And so on&#8230;&#8230;&#8230;&#8230;&#8230;</p>
<p>The results will be discussed in the next post where we dissect what we have just done.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/programming-language/blocks-for-transactions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks and Iterators (Part 2)</title>
		<link>http://easyrubyonrailsprogramming.com/programming-language/blocks-and-iterators-part-2/</link>
		<comments>http://easyrubyonrailsprogramming.com/programming-language/blocks-and-iterators-part-2/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 09:59:58 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[Iterators]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/programming-language/blocks-and-iterators-part-2/</guid>
		<description><![CDATA[
Anytime the &#8220;yield&#8221; statement is called upon it calls on the chunk of code within the block executing it returning control to where the yield statement was called continuing on its way till the process is finished. That&#8217;s where the magic of Ruby is, that a block can be made to function like a method [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dotnetfunda.com/articles/article135.aspx"><img src="/wp-content/uploads/scraped/28.jpg"/></a>
<p>Anytime the &#8220;yield&#8221; statement is called upon it calls on the chunk of code within the block executing it returning control to where the yield statement was called continuing on its way till the process is finished. That&#8217;s where the magic of Ruby is, that a block can be made to function like a method in itself. This allows processes to embedded and used again and again with minimal coding required to achieve the desired result. The Following post would have blocks used as transactional controllers which use them to do a process that is similar somewhat to the way methods work when they are called upon.</p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/programming-language/blocks-and-iterators-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks and Iterators (Part 1)</title>
		<link>http://easyrubyonrailsprogramming.com/development/blocks-and-iterators-part-1/</link>
		<comments>http://easyrubyonrailsprogramming.com/development/blocks-and-iterators-part-1/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 09:58:52 +0000</pubDate>
		<dc:creator>Avatar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming Basics]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[Iterators]]></category>

		<guid isPermaLink="false">http://easyrubyonrailsprogramming.com/development/blocks-and-iterators-part-1/</guid>
		<description><![CDATA[
An iterator is a method of calling on a block of code which is somewhat similar to C, Java or Perl, somewhat. The usage of iterators in Ruby does something different as opposed to other languages that share similar functions. Initially a block normally appears adjacent a method or call, that call statement is written [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://snippets.amanzi.org/2007/05/ruby-blocks-and-iterators.html"><img src="/wp-content/uploads/scraped/27.jpg"/></a>
<p>An iterator is a method of calling on a block of code which is somewhat similar to C, Java or Perl, somewhat. The usage of iterators in Ruby does something different as opposed to other languages that share similar functions. Initially a block normally appears adjacent a method or call, that call statement is written immediately after the method&#8217;s last parameter. Next, the chunk of code contained within the block is not done as it is executed rather it is remembered then has the code continue into the method. Then the block can be called as if it were a method in itself with the use of the &#8220;yield&#8221; statement. </p>
]]></content:encoded>
			<wfw:commentRss>http://easyrubyonrailsprogramming.com/development/blocks-and-iterators-part-1/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>
	</channel>
</rss>
