<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Dyba&#039;s Weblog</title>
	<atom:link href="http://dyba.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dyba.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Mon, 08 Aug 2011 06:29:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dyba.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Dyba&#039;s Weblog</title>
		<link>http://dyba.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dyba.wordpress.com/osd.xml" title="Dyba&#039;s Weblog" />
	<atom:link rel='hub' href='http://dyba.wordpress.com/?pushpress=hub'/>
		<item>
		<title>*** extconf.rb failed ***</title>
		<link>http://dyba.wordpress.com/2011/06/25/extconf-rb-failed/</link>
		<comments>http://dyba.wordpress.com/2011/06/25/extconf-rb-failed/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 05:24:58 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=211</guid>
		<description><![CDATA[The Error Impeding My Contributions On my way to contribute to the Rails Guides, after pulling from my cloned copy of the docrails repository on Github and running the bundle install command, an error stopped me: I am using MacPorts on my machine so if you&#8217;re having the same problem and are not using MacPorts [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=211&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>The Error Impeding My Contributions</h3>
<p>On my way to contribute to the Rails Guides, after pulling from my cloned copy of the docrails repository on Github and running the bundle install command, an error stopped me:</p>
<p><pre class="brush: bash;">
danieldyba@P4R15 Sat Jun 25 19:35 [ ~/Ruby/docrails ]
&gt;_ bundle install
 #... installation of other gems omitted
 Installing pg (0.11.0) with native extensions /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
 checking for pg_config... no
 No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
 checking for libpq-fe.h... no
 Can't find the 'libpq-fe.h header
 *** extconf.rb failed ***
 Could not create Makefile due to some reason, probably lack of
 necessary libraries and/or headers. Check the mkmf.log file for more
 details. You may need configuration options.
Provided configuration options:
 --with-opt-dir
 --without-opt-dir
 --with-opt-include
 --without-opt-include=${opt-dir}/include
 --with-opt-lib
 --without-opt-lib=${opt-dir}/lib
 --with-make-prog
 --without-make-prog
 --srcdir=.
 --curdir
 --ruby=/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
 --with-pg
 --without-pg
 --with-pg-dir
 --without-pg-dir
 --with-pg-include
 --without-pg-include=${pg-dir}/include
 --with-pg-lib
 --without-pg-lib=${pg-dir}/lib
 --with-pg-config
 --without-pg-config
 --with-pg_config
 --without-pg_config
Gem files will remain installed in /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@DocRails/gems/pg-0.11.0 for inspection.
 Results logged to /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@DocRails/gems/pg-0.11.0/ext/gem_make.out
 from /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:511:in `block in build_extensions'
 from /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `each'
 from /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `build_extensions'
 from /Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:159:in `install'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/source.rb:101:in `block in install'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:78:in `preserve_paths'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/source.rb:91:in `install'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/installer.rb:58:in `block (2 levels) in run'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:93:in `with_build_args'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/installer.rb:57:in `block in run'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/spec_set.rb:12:in `block in each'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/spec_set.rb:12:in `each'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/spec_set.rb:12:in `each'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/installer.rb:49:in `run'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/installer.rb:8:in `install'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/cli.rb:222:in `install'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/task.rb:22:in `run'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/vendor/thor.rb:246:in `dispatch'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/base.rb:389:in `start'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.14/bin/bundle:13:in `'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/bin/bundle:19:in `load'
 from /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@global/bin/bundle:19:in `'
 danieldyba@P4R15 Sat Jun 25 19:35 [ ~/Ruby/docrails ]
&gt;_
</pre></p>
<p>I am using MacPorts on my machine so if you&#8217;re having the same problem and are not using MacPorts then this guide will probably not help you; however, you may learn something that could lead you in the right direction.</p>
<p>Well, I followed the instructions on that error message and looked for my mkmf.log file:</p>
<pre>&gt;_ cat /Users/danieldyba/.rvm/gems/ruby-1.9.2-p180@DocRails/gems/pg-0.11.0/ext/mkmf.log
 find_executable: checking for pg_config... -------------------- no
--------------------
find_header: checking for libpq-fe.h... -------------------- no
"gcc -o conftest -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/x86_64-darwin10.7.0 -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby/backward -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe conftest.c -L. -L/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/lib -L. -lruby.1.9.1-static -lpthread -ldl -lobjc "
 checked program was:
 /* begin */
 1: #include "ruby.h"
 2:
 3: int main() {return 0;}
 /* end */
"gcc -E -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/x86_64-darwin10.7.0 -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1/ruby/backward -I/Users/danieldyba/.rvm/rubies/ruby-1.9.2-p180/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe conftest.c -o conftest.i"
 conftest.c:3:22: error: libpq-fe.h: No such file or directory
 checked program was:
 /* begin */
 1: #include "ruby.h"
 2:
 3: #include /* end */
--------------------
danieldyba@P4R15 Sat Jun 25 20:07 [ ~/Ruby/docrails ]
 &gt;_</pre>
<h3>One Tool Can&#8217;t find Another</h3>
<p>The trouble seems to be that Bundler can&#8217;t find the executable file pg_config. After a little research, I found out that I need to have Postgresql installed on my machine. So I did that with the command:</p>
<pre>sudo port install postgresql90</pre>
<p>Next, I checked to see where MacPorts installed Postgresql, in particular, where it installed the pg_config file:</p>
<pre>&gt;_ find /opt -name pg_config
 /opt/local/lib/postgresql90/bin/pg_config
 /opt/local/var/macports/software/postgresql90/9.0.4_0/opt/local/lib/postgresql90/bin/pg_config</pre>
<p>Looks like the file is saved in /opt/local/lib/postgresql90/bin/pg_config. I will have to tell Bundler about where the pg_config file is located:</p>
<pre>bundle config build.pg --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config</pre>
<p>That will add a line to my Bundler config file like so:</p>
<pre> &gt;_ cat ~/.bundle/config
 ---
 BUNDLE_BUILD__PG: --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config</pre>
<p>And now we&#8217;re ready to rock and roll. Run the &#8220;bundle install&#8221; command again and that error will go away.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/211/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=211&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2011/06/25/extconf-rb-failed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>
	</item>
		<item>
		<title>Mixing Modules with Classes &#8211; Class Methods</title>
		<link>http://dyba.wordpress.com/2011/02/11/mixing-modules-with-classes-class-methods/</link>
		<comments>http://dyba.wordpress.com/2011/02/11/mixing-modules-with-classes-class-methods/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 20:00:30 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[class_method]]></category>
		<category><![CDATA[extend]]></category>
		<category><![CDATA[mixin]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=184</guid>
		<description><![CDATA[Ned wanted to add more functionality to the Dog class he created. This time, instead of organizing methods inside a module class and making the module methods available to all instances of the Dog class, he wanted to create a module class that made its methods available to the Dog class as class methods. &#8220;I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=184&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ned wanted to add more functionality to the Dog class he created. This time, instead of organizing methods inside a module class and making the module methods available to all instances of the Dog class, he wanted to create a module class that made its methods available to the Dog class as class methods. </p>
<p>&#8220;I know this much,&#8221; thought Ned, &#8220;what I did last time won&#8217;t get what I want this time. But what would be the first step?&#8221; He pondered a few moments and spoke aloud. &#8220;The last time I took instance methods from a module&#8230;&#8221;</p>
<p><pre class="brush: ruby;">
module Actions
  def bark
    &quot;Woof!&quot;
  end
end
</pre><br />
&#8220;&#8230; and included it into the Dog class.&#8221;<br />
<pre class="brush: ruby;">
class Dog
  include Actions
end
</pre><br />
Ned began typing.<br />
<pre class="brush: ruby;">

module Attributes
	def breedable?
		true
	end

	def latin_name
		&quot;Canis&quot;
	end

	def has_four_legs?
		true
	end
end
</pre><br />
&#8220;So here&#8217;s the module whose instance methods I want to include in the Dog class as class methods. And I want to be able to do this&#8230;&#8221;<br />
<pre class="brush: bash;">
ruby-1.9.2-p136 :002 &gt; Dog.has_four_legs?
</pre><br />
Having learned from last time, Ned caught himself and said, &#8220;Oh, I better get a test suite running first.&#8221;<br />
<pre class="brush: ruby;">
require 'test/unit'
require './module'

class ModuleTest &lt; Test::Unit::TestCase

	def test_canine_attributes
		assert_equal(true, Dog.breedable?)
		assert_equal(true, Dog.has_four_legs?)
		assert_equal(&quot;Canis&quot;, Dog.latin_name)
	end
end
</pre><br />
&#8220;And can&#8217;t forget the Rakefile to run tests easily&#8230;&#8221;<br />
<pre class="brush: ruby;">
require 'rake/testtask'

Rake::TestTask.new do |t|
	t.libs &lt;&lt; &quot;test&quot;
	t.test_files = FileList['test/**/*_test.rb']
	t.verbose = true
end
</pre><br />
&#8220;Now to check my file structure looks good&#8230;&#8221;<br />
<pre class="brush: bash;">
&gt;_ ls -R
Rakefile	module.rb	test

./test:
module_test.rb
</pre><br />
&#8220;Great!&#8221; said Ned. &#8220;Just for kicks, I&#8217;ll write code I know won&#8217;t work.&#8221;<br />
<pre class="brush: ruby; highlight: [16];">
module Attributes
	def breedable?
		true
	end

	def latin_name
		&quot;Canis&quot;
	end

	def has_four_legs?
		true
	end
end

class Dog
	include Attributes
end
</pre><br />
&#8220;And when I run the &#8216;rake test&#8217; command from the Terminal&#8230;&#8221;<br />
<pre class="brush: bash;">

&gt;_ rake test
(in /Users/Paintdexter/ruby/module_examples/module_example_02)
/Users/Paintdexter/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I&quot;lib:test&quot; &quot;/Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader.rb&quot; &quot;test/module_test.rb&quot; 
Loaded suite /Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
E
Finished in 0.000681 seconds.

  1) Error:
test_canine_attributes(ModuleTest):
NoMethodError: undefined method `breedable?' for Dog:Class
    test/module_test.rb:7:in `test_canine_attributes'

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips

Test run options: --seed 33524
rake aborted!
Command failed with status (1): [/Users/Paintdexter/.rvm/rubies/ruby-1.9.2-...]

(See full trace by running task with --trace)
</pre><br />
&#8220;Just as expected,&#8221; nodded Ned. &#8220;Ok, I&#8217;ll remove that line of code and jump into IRB&#8221;.<br />
<pre class="brush: ruby;">
module Attributes
	def breedable?
		true
	end

	def latin_name
		&quot;Canis&quot;
	end

	def has_four_legs?
		true
	end
end

class Dog
end
</pre><br />
<pre class="brush: bash; auto-links: false;">
&gt;_ irb
ruby-1.9.2-p136 :001 &gt; require './module'
 =&gt; true 
ruby-1.9.2-p136 :002 &gt; Dog.methods
 =&gt; [:allocate, :new, :superclass, :freeze, :===, :==, :&lt;=&gt;, :&lt;, :&lt;=, :&gt;, :&gt;=, :to_s, :included_modules, :include?, :name, :ancestors, :instance_methods, :public_instance_methods, :protected_instance_methods, :private_instance_methods, :constants, :const_get, :const_set, :const_defined?, :const_missing, :class_variables, :remove_class_variable, :class_variable_get, :class_variable_set, :class_variable_defined?, :module_exec, :class_exec, :module_eval, :class_eval, :method_defined?, :public_method_defined?, :private_method_defined?, :protected_method_defined?, :public_class_method, :private_class_method, :autoload, :autoload?, :instance_method, :public_instance_method, :nil?, :=~, :!~, :eql?, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :__id__, : object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__] 
ruby-1.9.2-p136 :003 &gt;
</pre><br />
&#8220;That&#8217;s a whole lot of methods!&#8221; said Ned as his eyes scanned the several lines of output. &#8220;Out of all these, I&#8217;m gonna pick&#8230;.&#8221; Ned thought for a moment and finally decided, &#8220;the extend method.&#8221; He typed the following in the Terminal window.<br />
<pre class="brush: bash;">
&gt;_ ri extend
</pre><br />
Ned watched as the screen gave way to a whole page of content.<br />
<pre class="brush: bash;">
= .extend

(from ruby core)
=== Implementation from Object
------------------------------------------------------------------------------
  obj.extend(module, ...)    -&gt; obj

------------------------------------------------------------------------------

Adds to obj the instance methods from each module given as a parameter.

       module Mod
         def hello
           &quot;Hello from Mod.\n&quot;
         end
       end

       class Klass
         def hello
           &quot;Hello from Klass.\n&quot;
         end
       end

       k = Klass.new
       k.hello         #=&gt; &quot;Hello from Klass.\n&quot;
       k.extend(Mod)   #=&gt; #&lt;Klass:0x401b3bc8&gt;
       k.hello         #=&gt; &quot;Hello from Mod.\n&quot;
</pre><br />
&#8220;This looks close to what I want except I want to use this on a class.&#8221; Ned caught himself, &#8220;But I can use this on any object, and that includes a class object! But how would I make my example use the extend method?&#8221; Just then Rich made his way past Ned&#8217;s cubicle. &#8220;Hey Rich!&#8221; called Ned. &#8220;I need you for a minute.&#8221; Rich made his way over with a cup of hazelnut coffee on hand. &#8220;How can I use the extend method in my class to make the instance methods of my Attributes module available to my Dog class as class methods?&#8221; Rich asked, &#8220;Well, do you see how that example calls the extend method on &#8216;k&#8217; which is an instance of Klass?&#8221; &#8220;Yeah, I see that,&#8221; said Ned. Rich continued, &#8220;So you need to call the extend method while inside your class object.&#8221; Ned said, &#8220;You mean like this?&#8221;<br />
<pre class="brush: ruby;">
class Dog
	extend Attributes
end
</pre><br />
&#8220;Precisely!&#8221; said Rich. &#8220;Go ahead and run your tests.&#8221; Ned ran the &#8216;rake test&#8217; command in the Terminal:<br />
<pre class="brush: bash;">

&gt;_ rake test
(in /Users/Paintdexter/ruby/module_examples/module_example_02)
/Users/Paintdexter/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I&quot;lib:test&quot; &quot;/Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader.rb&quot; &quot;test/module_test.rb&quot; 
Loaded suite /Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.
Finished in 0.000629 seconds.

1 tests, 3 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 20387
</pre><br />
&#8220;Sweet!&#8221; cried Ned with excitement. &#8220;Do you know why that works?&#8221; asked Rich. &#8220;Kinda,&#8221; hesitated Ned. Rich explained, &#8220;What&#8217;s implied in your code is that you are calling the extend method on self. And in this case, since you are inside the scope of a class, self is the Dog class. So, what is really happening, looks more like this&#8221;<br />
<pre class="brush: ruby;">
class Dog
	self.extend Attributes
end
</pre><br />
&#8220;If you look back at the output you got from running the &#8216;ri&#8217; command, you&#8217;ll see that extend adds the instance methods of a module to the object. In this case, your object is self, or the Dog class. So you add the instance methods of the Attributes module to the Dog class. These instance methods become the class methods of the Dog class.&#8221;<br />
&#8220;Ah!&#8221; said Ned. &#8220;That makes sense.&#8221;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=184&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2011/02/11/mixing-modules-with-classes-class-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>
	</item>
		<item>
		<title>Mixing Modules with Classes &#8211; Where Order Matters</title>
		<link>http://dyba.wordpress.com/2011/02/09/mixing-modules-with-classes/</link>
		<comments>http://dyba.wordpress.com/2011/02/09/mixing-modules-with-classes/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 15:00:44 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[mixin]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=148</guid>
		<description><![CDATA[&#8220;Confound it!&#8221; cried Ned. Frustrated, he shoved his keyboard and crossed his arms. &#8220;Why doesn&#8217;t it work?&#8221; He leaned back in and began a Google search for the answer to his problem. &#8220;Hey chap! What&#8217;s got you fuming?&#8221; inquired Rich. &#8220;I&#8217;m trying to mix a module in with a class, but I can&#8217;t seem to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=148&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8220;Confound it!&#8221; cried Ned. Frustrated, he shoved his keyboard and crossed his arms. &#8220;Why doesn&#8217;t it work?&#8221; He leaned back in and began a Google search for the answer to his problem. &#8220;Hey chap! What&#8217;s got you fuming?&#8221; inquired Rich. &#8220;I&#8217;m trying to mix a module in with a class, but I can&#8217;t seem to get it right,&#8221; complained Ned. &#8220;What exactly are you trying to accomplish?&#8221; asked Rich. &#8220;So, here&#8217;s what I&#8217;m trying to do. You see, I define a module with a method here. And I&#8217;m trying to get an instance of my class to use that method. So I include the module in the class, but it just doesn&#8217;t work!&#8221;</p>
<p><pre class="brush: ruby;">
class Dog
  include Actions
end

module Actions
  def bark
    &quot;Woof!&quot;
  end
end
</pre></p>
<p>&#8220;What&#8217;s the error message you&#8217;re getting?&#8221; asked Rich. &#8220;Well, I&#8217;m getting an uninitialized constant error,&#8221; said Ned with a sigh.</p>
<p><pre class="brush: bash;">

ruby-1.9.2-p136 :001 &gt; require './module'
NameError: uninitialized constant Dog::Actions
	from /Users/Paintdexter/ruby/module_example_01/module.rb:2:in `&lt;class:Dog&gt;'
	from /Users/Paintdexter/ruby/module_example_01/module.rb:1:in `&lt;top (required)&gt;'
	from &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
	from &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
	from (irb):1
	from /Users/Paintdexter/.rvm/rubies/ruby-1.9.2-p136/bin/irb:17:in `&lt;main&gt;'
ruby-1.9.2-p136 :002 &gt; 
</pre></p>
<p>Rich poked his eyes around Ned&#8217;s screen, &#8220;Where&#8217;s your test suite?&#8221; Embarrassed, Ned managed a broken chuckle, &#8220;Oh right!&#8221; He pulled up a new window and began typing:</p>
<p><pre class="brush: ruby;">
require 'test/unit'
require './module'

class ModuleTest &lt; Test::Unit
</pre></p>
<p>Ned stopped typing. &quot;How does that go again?&quot; he asked. Rich spoke, &quot;Your ModuleTest will be a subclass of Test::Unit::TestCase.&quot; &quot;Oh right, right!&quot; interjected Ned. &quot;Now, set up the object you&#039;ll be testing. In this case, it will be an instance of Dog,&quot; continued Rich. &quot;Do you remember the rest?&quot; asked Rich. &#8220;Yup,&#8221; said Ned confidently, &#8220;assert_equal and voila&quot;:<br />
<pre class="brush: ruby;">
require 'test/unit'
require './module'

class ModuleTest &lt; Test::Unit::TestCase

	def setup
		@dog = Dog.new
	end

	def test_an_instance_of_a_dog_should_bark
		assert_equal(&quot;Woof!&quot;, @dog.bark)
	end
end
</pre></p>
<p>&#8220;Let&#8217;s go ahead and add a Rakefile to make running tests easier,&#8221; invited Rich. &#8220;Create a file called Rakefile and add the following lines below.&#8221;<br />
<pre class="brush: ruby;">
require 'rake/testtask'

Rake::TestTask.new do |t|
	t.libs &lt;&lt; &quot;test&quot;
	t.test_files = FileList['test/**/*_test.rb']
	t.verbose = true
end
</pre><br />
Rich went on, &#8220;The first line lets you create an instance of Rake::TestTask so you can run your tests. The fourth line includes a directory in your current directory called &#8216;test&#8217;. The fifth line will grab any files in the &#8216;test&#8217; directory that end in &#8216;_test.rb&#8217;. And the last line gives us more information when we encounter an error in the Terminal after we run the command. Go ahead and create a directory and store your test file there. Your file structure should look like this&#8221;</p>
<p><pre class="brush: bash;">
&gt;_ ls -R
Rakefile	module.rb	test

./test:
module_test.rb
</pre></p>
<p>&#8220;Now, let&#8217;s get back to the problem,&#8221; continued Rich.<br />
<pre class="brush: bash;">

ruby-1.9.2-p136 :001 &gt; require './module'
NameError: uninitialized constant Dog::Actions
	from /Users/Paintdexter/ruby/module_example_01/module.rb:2:in `&lt;class:Dog&gt;'
	from /Users/Paintdexter/ruby/module_example_01/module.rb:1:in `&lt;top (required)&gt;'
	from &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
	from &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
	from (irb):1
	from /Users/Paintdexter/.rvm/rubies/ruby-1.9.2-p136/bin/irb:17:in `&lt;main&gt;'
ruby-1.9.2-p136 :002 &gt; 
</pre></p>
<p>&#8220;If you try running the &#8216;rake test&#8217; command in the Terminal, you&#8217;ll get similar output.&#8221; Ned went ahead and did so:<br />
<pre class="brush: bash;">
&gt;_ rake test
(in /Users/Paintdexter/ruby/module_example_01)
/Users/Paintdexter/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I&quot;lib:test&quot; &quot;/Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader.rb&quot; &quot;test/module_test.rb&quot; 
/Users/Paintdexter/ruby/module_example_01/module.rb:2:in `&lt;class:Dog&gt;': uninitialized constant Dog::Actions (NameError)
	from /Users/Paintdexter/ruby/module_example_01/module.rb:1:in `&lt;top (required)&gt;'
	from &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
	from &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
	from test/module_test.rb:2:in `&lt;top (required)&gt;'
	from /Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
	from /Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `block in &lt;main&gt;'
	from /Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
	from /Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `&lt;main&gt;'
rake aborted!
Command failed with status (1): [/Users/Paintdexter/.rvm/rubies/ruby-1.9.2-...]

(See full trace by running task with --trace)
</pre><br />
&#8220;It looks like IRB doesn&#039;t see the Actions module. Particularly, there seems to be something wrong in line 2, where you call the include method and pass the Actions module as a parameter. Let me ask you something, Ned. Do you think the order of where you defined the Actions module might matter?&quot; Ned pondered for a moment and cocked his head. &quot;Let&#039;s try switching the order around,&quot; invited Rich. So Ned went right ahead and did just as Rich had said:</p>
<p><pre class="brush: ruby;">
module Actions
	def bark
		&quot;Woof!&quot;
	end
end

class Dog
	include Actions
end
</pre></p>
<p>Ned returned to the Terminal.</p>
<p><pre class="brush: ruby;">
ruby-1.9.2-p136 :001 &gt; require &#039;./module&#039;
 =&gt; true 
ruby-1.9.2-p136 :002 &gt; 
</pre></p>
<p>&quot;Great!&quot; said Ned ecstatically, &quot;That did it! The order DOES matter.&quot; He lost no time and proceeded to see his creation work flawlessly:</p>
<p><pre class="brush: ruby;">
ruby-1.9.2-p136 :002 &gt; spot = Dog.new
 =&gt; #&lt;Dog:0x000001010089d8&gt; 
ruby-1.9.2-p136 :003 &gt; spot.bark
 =&gt; &quot;Woof!&quot; 
ruby-1.9.2-p136 :004 &gt; 
</pre></p>
<p>&quot;Will you look at that!&quot; reveled Ned, &quot;It works!&quot; He ran the next command:</p>
<p><pre class="brush: bash;">
&gt;_ rake test
(in /Users/Paintdexter/ruby/module_example_01)
/Users/Paintdexter/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I&quot;lib:test&quot; &quot;/Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader.rb&quot; &quot;test/module_test.rb&quot; 
Loaded suite /Users/Paintdexter/.rvm/gems/ruby-1.9.2-p136@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.
Finished in 0.000605 seconds.

1 tests, 1 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 15619
</pre><br />
A smile broke through Ned&#8217;s face.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=148&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2011/02/09/mixing-modules-with-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>
	</item>
		<item>
		<title>Cucumber Ambiguous Match Errors</title>
		<link>http://dyba.wordpress.com/2010/10/15/cucumber-ambiguous-match-errors/</link>
		<comments>http://dyba.wordpress.com/2010/10/15/cucumber-ambiguous-match-errors/#comments</comments>
		<pubDate>Sat, 16 Oct 2010 03:04:35 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[webrat]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=110</guid>
		<description><![CDATA[Have you tried running Cucumber with webrat and had a hard time getting past the &#8220;Ambigous match&#8221; error? The webrat matchers are a series of Cucumber steps written using Regular Expressions. This means Cucumber will match the Webrat steps against the Cucumber steps you write. I am going to assume you&#8217;ve already got Cucumber and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=110&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have you tried running Cucumber with webrat and had a hard time getting past the &#8220;Ambigous match&#8221; error? The webrat matchers are a series of Cucumber steps written using Regular Expressions. This means Cucumber will match the Webrat steps against the Cucumber steps you write.</p>
<p>I am going to assume you&#8217;ve already got Cucumber and Webrat installed in your machine and configured it for your Rails app. By the way, I&#8217;m using Rails 3, Cucumber 0.9.2, Cucumber-rails 0.3.2, Webrat 0.7.2 beta1, and Clearance 0.9.0.rc9. I also ran the command:<br />
<code><br />
rails generate cucumber:install --webrat<br />
</code></p>
<p>Let&#8217;s take a simple example: I want to check that I go to the right page on my web app. In Cucumber, you&#8217;d write this:<br />
<code><br />
When /^I go to the sign up page$/ do<br />
end<br />
</code><br />
But if you look at your webrat file under /features/step_definitions/web_steps.rb, you&#8217;ll find this entry:<br />
<code><br />
When /^(?:|I )go to (.+)$/ do |page_name|<br />
visit path_to(page_name)<br />
end<br />
</code><br />
What this tells you is that Cucumber will match this Webrat step with a statement like &#8220;I go to the sign up page&#8221;. I tried this:<br />
<code><br />
When /^I go to the sign up page$/ do |sign_up_page|<br />
end<br />
</code><br />
That gave me that nasty &#8220;Ambiguous match&#8221; error. Well, what&#8217;s wrong? I took a look at the regular expression again:<br />
<code><br />
When /^(?:|I )go to <strong>(.+)</strong>$/ do |page_name|<br />
visit path_to(page_name)<br />
end<br />
</code><br />
Now, I ran a test in irb and saw that this code:<br />
<code><br />
"I go to the sign in page".scan(/^(?:|I )go to (.+)$/)<br />
</code><br />
Gives the output:<br />
<code><br />
=&gt; [["the sign in page"]]<br />
</code><br />
Which basically tells me that the Webrat step should have matched my Cucumber step. Something told me that perhaps I should tweak my Cucumber step. So I did:<br />
<code><br />
When /^I go to the 'sign up page'$/ do |sign_up_page|<br />
end<br />
</code><br />
<code><br />
When /^I go to the "sign up page"$/ do |sign_up_page|<br />
end<br />
</code><br />
<code><br />
When /^I go to the SignUpPage$/ do |sign_up_page|<br />
end<br />
</code><br />
<code><br />
When /^I go to the 'the sign up page'$/ do<br />
end<br />
</code><br />
It turns out that all these examples <font color="green"><b>passed</b></font>. So that made me conclude that Cucumber couldn&#8217;t properly interpret the Webrat statements because it <strong>doesn&#8217;t like the spaces I had in my Cucumber step</strong>. Also, it needed something to clearly point out what (.+) meant in my statement. <strong>To get Cucumber to understand what I meant, I enclosed the phrase that would be interpreted as a parameter in single quotes</strong>. Perhaps, it couldn&#8217;t interpret the (.+) correctly. For now, I&#8217;m going to live with it and make it a point to read the cucumber-rails gem to find out what&#8217;s really going on.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=110&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2010/10/15/cucumber-ambiguous-match-errors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>
	</item>
		<item>
		<title>RSpec Tutorial #001</title>
		<link>http://dyba.wordpress.com/2010/09/03/rspec-tutorial-001/</link>
		<comments>http://dyba.wordpress.com/2010/09/03/rspec-tutorial-001/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 21:19:41 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=86</guid>
		<description><![CDATA[Requirements Ruby 1.8.7 (2009-06-12 patchlevel 174) RSpec 1.3.0 I started learning RSpec a few days ago. Well, I started much earlier than that, but at that time I was still new to Ruby. With a year&#8217;s worth of experience with Ruby now, I feel more confident to tackle RSpec to test my Ruby code. When [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=86&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table border="0">
<tbody>
<tr>
<td colspan="2"><strong>Requirements</strong></td>
</tr>
<tr>
<td width="30%">Ruby</td>
<td>1.8.7 (2009-06-12 patchlevel 174)</td>
</tr>
<tr>
<td>RSpec</td>
<td>1.3.0</td>
</tr>
</tbody>
</table>
<p>I started learning RSpec a few days ago. Well, I started much earlier than that, but at that time I was still new to Ruby. With a year&#8217;s worth of experience with Ruby now, I feel more confident to tackle RSpec to test my Ruby code. When you&#8217;re new to Ruby testing doesn&#8217;t make much sense: how can I test code when I don&#8217;t even know how to write it properly? I definitely think you need to have to play with the language long enough to understand it well enough before you dive into writing unit and more complicated tests.</p>
<p>Here&#8217;s some RSpec code I found on the RSpec book by David Chelimsky:</p>
<pre>describe Stack do</pre>
<pre>     before(:each) do</pre>
<pre>          @stack = Stack.new</pre>
<pre>          @stack.push :item</pre>
<pre>     end</pre>
<pre>     describe "#peek" do</pre>
<pre>          it "should return the top element" do</pre>
<pre>               @stack.peek.should == :item</pre>
<pre>          end</pre>
<pre>          it "should not remove the top element" do</pre>
<pre>               @stack.peek</pre>
<pre>               @stack.size.should == 1</pre>
<pre>          end</pre>
<pre>     end</pre>
<pre>     describe "#pop" do</pre>
<pre>          it "should return the top element" do</pre>
<pre>               @stack.pop.should == :item</pre>
<pre>          end</pre>
<pre>          it "should remove the top element" do</pre>
<pre>               @stack.pop</pre>
<pre>               @stack.size.should == 0</pre>
<pre>          end</pre>
<pre>     end</pre>
<pre>end</pre>
<p>The first describe statement is the outermost block. Do you see the do and end keywords? We insert a statement after the describe keyword to give a name to our test. We are testing an object called Stack.</p>
<p>The before(:each) statement is the next block inside the outermost block. Inside the before(:each) block, we specify what code we want to run before running the inner describe statements. For every describe statement, the code in the before(:each) block will run beforehand. In the before(:each) block we create a new Stack object and push an item onto the stack.</p>
<p>Looking at the methods of this Stack object, we see that it acts very much like an Array. An array has a pop method and a push method. Let&#8217;s keep that in mind for later.</p>
<p>The next describe statement has a description of &#8220;#peek&#8221;. By convention, the hash sign signifies that this is a method inside of the Stack object. The it statements specify how the peek method should behave. Note that the peek method should show us what is on top of the stack without removing that item from the stack. The should method is made available via RSpec. You call this method on your target object and check its output with the == sign. So in our case, we want to call the method peek on @stack and it should be equal to 0. Translating this to code RSpec can interpret leads to @stack.peek.should == 0.</p>
<p>The next describe statement has a description of &#8220;#pop&#8221;. This is your standard pop method that comes with an Array: when you call the pop method, the item on the stack gets removed.</p>
<p>Now, what is the code we should be writing to make these tests pass?</p>
<p>We can start by creating a Stack class that subclasses the Array class:</p>
<pre>class Stack &lt; Array</pre>
<pre>end</pre>
<p>Run the test using the &#8216;spec&#8217; command. We add the color option so we can see red and green colored tests when they fail or pass, respectively. The other option we add, let&#8217;s us see the describe statements in a nested fashion:</p>
<p>&gt; spec stack.rb &#8211;color &#8211;format nested</p>
<pre>Stack</pre>
<pre>     #peek</pre>
<pre><span style="color:#ff0000;">          should return the top element (FAILED - 1)</span></pre>
<pre><span style="color:#ff0000;">          should not remove the top element (FAILED - 2)</span></pre>
<pre>     #pop</pre>
<pre><span style="color:#339966;">        should return the top element</span></pre>
<pre><span style="color:#339966;">        should remove the top element</span></pre>
<pre>1) <span style="color:#ff0000;">NoMethodError in 'Stack#peek should return the top element'</span></pre>
<pre><span style="color:#ff0000;">undefined method `peek' for [:item]:Stack</span></pre>
<pre>./stack.rb:12:</pre>
<pre>2) <span style="color:#ff0000;">NoMethodError in 'Stack#peek should not remove the top element'</span></pre>
<pre><span style="color:#ff0000;">undefined method `peek' for [:item]:Stack</span></pre>
<pre>./stack.rb:16:</pre>
<p>You&#8217;ll see that we haven&#8217;t added any methods to the Stack class. Since we subclasses Stack with Array, we&#8217;ve covered the pop method. Now to do something about that peek method. You know that the Array class has a pop method. We want to use that but not on the object itself. Instead, perhaps, we can use a copy of the self object that doesn&#8217;t modify the self object.</p>
<p>If you take a look at the methods available on self, one of them is dup. This will create a shallow copy of self, you can modify the new object without a worry that you&#8217;ll modify self.</p>
<pre>class Stack &lt; Array</pre>
<pre>     def peek</pre>
<pre>          self.dup.pop</pre>
<pre>     end</pre>
<pre>end</pre>
<p>Now, run the &#8216;spec&#8217; command again, and you&#8217;ll get the following output:</p>
<p>&gt; spec stack.rb &#8211;color &#8211;format nested</p>
<pre>Stack
<pre>     #peek
<span style="color:#339966;">          should return the top element</span>
<span style="color:#339966;">          should not remove the top element</span>
     #pop
<span style="color:#339966;">          should return the top element</span>
<span style="color:#339966;">          should remove the top element</span></pre>
<p>Finished in 0.002524 seconds<br />
<span style="color:#339966;">4 examples, 0 failures</span></pre>
<p>Great! We got our tests to work successfully!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=86&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2010/09/03/rspec-tutorial-001/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>
	</item>
		<item>
		<title>Git Starter (Tutorial)</title>
		<link>http://dyba.wordpress.com/2010/06/13/git-starter-tutorial/</link>
		<comments>http://dyba.wordpress.com/2010/06/13/git-starter-tutorial/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 20:21:31 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=61</guid>
		<description><![CDATA[I am hard at work on a web startup with a friend of mine. So naturally, I&#8217;ve not been able to add any recent posts. I do have ideas for plenty of posts but I&#8217;m still stitching the holes in my understanding. Working on a growing project calls for being able to keep track of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=61&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am hard at work on a web startup with a friend of mine. So naturally, I&#8217;ve not been able to add any recent posts. I do have ideas for plenty of posts but I&#8217;m still stitching the holes in my understanding.</p>
<p>Working on a growing project calls for being able to keep track of all the changes in your files efficiently. Enter Git. I&#8217;ve never used Git before. I started about a month ago. Here I would like to explain just enough to get you started on keeping track of your files. If you have been copy-pasting your project directories and renaming them with last revision dates, then you can chuck that way of doing things and simplify your life with Git.</p>
<p>To initialize a Git repository, create a folder, CD into it, and then type:</p>
<p>git init</p>
<p>This will create a hidden .git directory in which you&#8217;ll find all of the git files.<br />
I am using Git version 1.7.0. If you&#8217;re using this version, you&#8217;ll find the files below when you type &#8216;find .&#8217; in your Terminal window:</p>
<p>.<br />
./.git<br />
./.git/branches<br />
./.git/config<br />
./.git/description<br />
./.git/HEAD<br />
./.git/hooks<br />
./.git/hooks/applypatch-msg.sample<br />
./.git/hooks/commit-msg.sample<br />
./.git/hooks/post-commit.sample<br />
./.git/hooks/post-receive.sample<br />
./.git/hooks/post-update.sample<br />
./.git/hooks/pre-applypatch.sample<br />
./.git/hooks/pre-commit.sample<br />
./.git/hooks/pre-rebase.sample<br />
./.git/hooks/prepare-commit-msg.sample<br />
./.git/hooks/update.sample<br />
./.git/info<br />
./.git/info/exclude<br />
./.git/objects<br />
./.git/objects/info<br />
./.git/objects/pack<br />
./.git/refs<br />
./.git/refs/heads<br />
./.git/refs/tags</p>
<p>We&#8217;ll now create a new file:</p>
<p>echo &#8220;My First File&#8221; &gt; index.html</p>
<p>If you list your files, you&#8217;ll now see a file called index.html. If you now type<br />
&#8216;git status&#8217;, Git will tell you that index.html is not being tracked:</p>
<p># On branch master<br />
#<br />
# Initial commit<br />
#<br />
# Untracked files:<br />
#   (use &#8220;git add &#8230;&#8221; to include in what will be committed)<br />
#<br />
#	index.html<br />
nothing added to commit but untracked files present (use &#8220;git add&#8221; to track)</p>
<p>If you want Git to track a file, you need to carry out the command &#8216;git add type_your_file_name&#8217;. In our case, we would execute the command &#8216;git add index.html&#8217;. If you&#8217;re adding several files, for convenience, you can type the command &#8216;git add .&#8217;. This will tell Git to add all the untracked files.</p>
<p>Before you type the previous command, let&#8217;s take a look at what&#8217;s currently inside the git/objects directory. If you type &#8216;find .git/objects/&#8217; you&#8217;ll see the following:</p>
<p>.git/objects<br />
.git/objects/info<br />
.git/objects/pack</p>
<p>Now let&#8217;s go ahead and type &#8216;git add index.html&#8217;. We have now started to track index.html using Git. Let&#8217;s type &#8216;git status&#8217;:</p>
<p># On branch master<br />
#<br />
# Initial commit<br />
#<br />
# Changes to be committed:<br />
#   (use &#8220;git rm &#8211;cached &#8230;&#8221; to unstage)<br />
#<br />
#	new file:   index.html<br />
#</p>
<p>Now let&#8217;s run the command &#8216;find .git/objects&#8217;:</p>
<p>.git/objects<br />
.git/objects/e4<br />
.git/objects/e4/6f9d05b91b7ea6825a94d2a5f0b6f04f409d4e<br />
.git/objects/info<br />
.git/objects/pack</p>
<p>We now have a new object. So what just happened? Git performed some operations on the contents of the index.html file, calculated its SHA1 hash, and entered the contents of the file into the object store as a file. The name of this file is the hexadecimal representation of the SHA1 hash &#8216;e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e&#8217;. Note also how there&#8217;s a directory called &#8216;e4&#8242; and then there&#8217;s another directory with a longer hexadecimal string &#8217;6f9d05b91b7ea6825a94d2a5f0b6f04f409d4e&#8217;. Git breaks up the first two hexadecimal numbers of the hash and creates a directory out of it. The reason it does this is to optimize searching for files. Using this technique for storing objects, Git would only have to search<br />
through a maximum of 16 * 16 = 256 different folders during the first run through rather than searching through &#8216;n&#8217; files. (Note: Every hexadecimal number has 16 possible values). But what happened to our original index.html file? Run this command &#8216;git cat-file -p e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e&#8217;</p>
<p>My First File</p>
<p>But that&#8217;s exactly the contents of the file index.html we created earlier. Have you noticed how often I have harped on the contents of the file as being the primary thing Git focuses on when tracking files? Let&#8217;s try an experiment. Create a new directory and call it &#8216;new&#8217;. If you run &#8216;find .git/objects&#8217;, you&#8217;ll notice that nothing has changed. Running &#8216;git status&#8217; doesn&#8217;t say anything about there being a new directory. Now create a new file in the &#8216;new&#8217; directory and call it &#8216;index.html&#8217; and add the exact same contents you did in the first &#8216;index.html&#8217; file you created. If you run &#8216;git status&#8217;, Git will tell you that there are untracked files under the new directory:</p>
<p># On branch master<br />
#<br />
# Initial commit<br />
#<br />
# Changes to be committed:<br />
#   (use &#8220;git rm &#8211;cached &#8230;&#8221; to unstage)<br />
#<br />
#	new file:   index.html<br />
#<br />
# Untracked files:<br />
#   (use &#8220;git add &#8230;&#8221; to include in what will be committed)<br />
#<br />
#	new/</p>
<p>So now we&#8217;ll add new/index.html so Git can track it:</p>
<p>git add new/index.html</p>
<p>If you run &#8216;git status&#8217;, you&#8217;ll see this:</p>
<p># On branch master<br />
#<br />
# Initial commit<br />
#<br />
# Changes to be committed:<br />
#   (use &#8220;git rm &#8211;cached &#8230;&#8221; to unstage)<br />
#<br />
#	new file:   index.html<br />
#	new file:   new/index.html<br />
#</p>
<p>Now let&#8217;s run &#8216;find .git/objects&#8217;:</p>
<p>.git/objects<br />
.git/objects/e4<br />
.git/objects/e4/6f9d05b91b7ea6825a94d2a5f0b6f04f409d4e<br />
.git/objects/info<br />
.git/objects/pack</p>
<p>Nothing seems to have changed. Now let&#8217;s run the command &#8216;git ls-files -s&#8217;:</p>
<p>100644 e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e 0	index.html<br />
100644 e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e 0	new/index.html</p>
<p>Wait a minute! Both of those files have the exact same SHA1 hash! But they&#8217;re in different folders! How&#8217;s that possible? This is because Git tracks the contents of the file. You may now be thinking, well both files have the same name, maybe these values are the same because the file names are the same. Let&#8217;s create a new folder &#8216;retry&#8217;. Now we&#8217;ll call this file &#8216;public.html&#8217; and pass the exact same contents as the other files:</p>
<p>echo &#8220;My First File&#8221; &gt; public.html</p>
<p>Add this file to Git so that it can be tracked.</p>
<p>git add retry/public.html</p>
<p>And now list the files Git is tracking:</p>
<p>100644 e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e 0	index.html<br />
100644 e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e 0	new/index.html<br />
100644 e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e 0	retry/public.html</p>
<p>The SHA1 hashes are still all identical! Ok, now you should be<br />
convinced that Git tracks the contents of the files. So does that mean<br />
that Git doesn&#8217;t track the pathnames of files? No, Git uses a different<br />
object to do that. It&#8217;s called the tree object. Whenever you use the<br />
Git add or rm command, Git updates the index. The index is found in<br />
.git/index. When Git updates the index, it doesn&#8217;t create the tree<br />
objects right away. The Git add and rm commands update the index with<br />
the new pathname and contents of the file. If you want Git to create<br />
the tree objects, you can issue the &#8216;git write-tree&#8217; command. This is<br />
a low-level command, and in practice you won&#8217;t have to do this. Instead,<br />
using &#8216;git commit&#8217; will take care of creating these tree objects.</p>
<p>We have simply added files from our working directory to the index, but<br />
we have not yet added these staged files to the repository. When<br />
you issue the &#8216;git commit&#8217; command, Git will take the virtual tree objects<br />
in the index and create real tree objects that it will store in the<br />
.git/objects directory.</p>
<p>Now that we have three files in our stage, we will go ahead and commit<br />
these changes to our repository. To do this we will issue the &#8216;git commit&#8217;<br />
command. Git will then open your default editor. What Git wants you to do<br />
is to write a short message describing what you have committed, basically<br />
what changes have you made in this incremental step now being recorded<br />
to the repository. You may not want to get very detailed. I would recommend writing a one line overview of what this commit involved. Then you can separate that line with an empty line followed by a more detailed explanation of what you did if you like. Once you have finished, you can close the editor and you should see the changes Git has recorded.</p>
<p>[master (root-commit) 9ad35aa] My First Commit<br />
3 files changed, 3 insertions(+), 0 deletions(-)<br />
create mode 100644 index.html<br />
create mode 100644 new/index.html<br />
create mode 100644 retry/public.html</p>
<p>If you run the &#8216;git status&#8217; command, you see:</p>
<p># On branch master<br />
nothing to commit (working directory clean)</p>
<p>This means the working directory, the index, and the repository are all in<br />
agreement. All three are in sync. Now run the command &#8216;find .git/objects&#8217;:</p>
<p>.git/objects<br />
.git/objects/13<br />
.git/objects/13/a6860ac22bfb70e28db48be830127bd21c58aa<br />
.git/objects/43<br />
.git/objects/43/a062c5dda49e2e95ad8824e0611de31b383ce1<br />
.git/objects/96<br />
.git/objects/96/eaacc865733e873198c6a381bb17617b1872f1<br />
.git/objects/9a<br />
.git/objects/9a/d35aa68a0fd2ca186fe366dbe94bf53f683204<br />
.git/objects/e4<br />
.git/objects/e4/6f9d05b91b7ea6825a94d2a5f0b6f04f409d4e<br />
.git/objects/info<br />
.git/objects/pack</p>
<p>Type the following command &#8216;git cat-file -p type_your_sha1_hash_value&#8217;. The SHA1 hash &#8216;e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e&#8217; corresponds to the<br />
contents of the files &#8216;index.html&#8217;, &#8216;new/index.html&#8217;, and &#8216;retry/public.html&#8217;<br />
The other objects are tree and commit objects.</p>
<p>The first one &#8217;13a6860ac22bfb70e28db48be830127bd21c58aa&#8217; corresponds to the tree object that points to the file index.html under the &#8216;new&#8217; folder.</p>
<p>The second one &#8217;43a062c5dda49e2e95ad8824e0611de31b383ce1&#8242;<br />
corresponds to the tree object that points to the file public.html under the &#8216;retry&#8217; folder.</p>
<p>The third object &#8217;96eaacc865733e873198c6a381bb17617b1872f1&#8242; points to three objects: index.html, the &#8216;new&#8217; directory, and the &#8216;retry&#8217; directory. This is the output:</p>
<p>100644 blob e46f9d05b91b7ea6825a94d2a5f0b6f04f409d4e	index.html<br />
040000 tree 13a6860ac22bfb70e28db48be830127bd21c58aa	new<br />
040000 tree 43a062c5dda49e2e95ad8824e0611de31b383ce1	retry</p>
<p>Notice that this object contains three data unlike the other objects. You can also see that it contains objects we&#8217;ve already seen. </p>
<p>The last object is a commit object. When you run &#8216;git cat-file -p 9ad35aa68a0fd2ca186fe366dbe94bf53f683204&#8242;, you see the text below: </p>
<p>tree 96eaacc865733e873198c6a381bb17617b1872f1<br />
author Daniel Dyba  1276451901 -0700<br />
committer Daniel Dyba  1276451901 -0700</p>
<p>My First Commit</p>
<p>Notice how the tree object information is contained in this commit object. Using this object, you can build a visual diagram that looks like this:</p>
<p><a href="http://dyba.files.wordpress.com/2010/06/git-starter-tutorial-012.png"><img src="http://dyba.files.wordpress.com/2010/06/git-starter-tutorial-012.png?w=271&#038;h=300" alt="" title="Git Objects" width="271" height="300" class="aligncenter size-medium wp-image-82" /></a></p>
<p>Now, to use Git at the beginner level, you want to follow the process of creating files, adding these files to the index using the &#8216;git add&#8217; command, and finally committing your changes using the &#8216;git commit&#8217; command to synchronize the working directory, index, and repository.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=61&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2010/06/13/git-starter-tutorial/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>

		<media:content url="http://dyba.files.wordpress.com/2010/06/git-starter-tutorial-012.png?w=271" medium="image">
			<media:title type="html">Git Objects</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby script to connect to MySQL database</title>
		<link>http://dyba.wordpress.com/2010/03/03/ruby-script-to-connect-to-mysql-database/</link>
		<comments>http://dyba.wordpress.com/2010/03/03/ruby-script-to-connect-to-mysql-database/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 04:46:14 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=44</guid>
		<description><![CDATA[In this screencast, I&#8217;ll be writing a Ruby script to connect to a MySQL database. I&#8217;m using Ruby version 1.8.7 and the mysql gem version 2.8.1. To see this video with optimum quality, view it in HD. Here&#8217;s the code. Save this to a file called mysql-01.rb. Find the correct directory and using the Terminal [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=44&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this screencast, I&#8217;ll be writing a Ruby script to connect to a MySQL database. I&#8217;m using Ruby version 1.8.7 and the mysql gem version 2.8.1. To see this video with optimum quality, view it in HD.</p>
<div id="v-ViKkCJGn-1" class="video-player" style="width:600px;height:336px">
<embed id="v-ViKkCJGn-1-video" src="http://s0.videopress.com/player.swf?v=1.03&amp;guid=ViKkCJGn&amp;isDynamicSeeking=true" type="application/x-shockwave-flash" width="600" height="336" title="Using a Ruby Script to Connect to MySQL Database" wmode="direct" seamlesstabbing="true" allowfullscreen="true" allowscriptaccess="always" overstretch="true"></embed></div>
<p>Here&#8217;s the code. Save this to a file called mysql-01.rb. Find the correct directory and using the Terminal on a Mac OS X, type ruby mysql-01.rb.</p>
<pre style="font-size:12px;">require 'mysql'
begin
  db = Mysql.real_connect("localhost", "test", "testpass", "test")
  puts "Server version: " + db.get_server_info
rescue Mysql::Error =&gt; e
  puts "Error code: #{e.errno}"
  puts "Error message: #{e.error}"
  puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
ensure
  db.close if db
end</pre>
<p>If you get any errors while trying to do this, check to make sure that you have turned on your MySQL server. Also if you have not set rubygems to be the value of your RUBYOPT variable in the environment variables on your machine, you&#8217;ll get errors when you try to run the command &#8216;ruby mysql-01.rb&#8217; in the Terminal window.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=44&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" /><div><a href="http://dyba.wordpress.com/2010/03/03/ruby-script-to-connect-to-mysql-database/"><img alt="Using a Ruby Script to Connect to MySQL Database" src="http://videos.videopress.com/ViKkCJGn/ruby-script-connect-mysql-db_std.original.jpg" width="160" height="120" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2010/03/03/ruby-script-to-connect-to-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<enclosure url="http://videos.videopress.com/ViKkCJGn/ruby-script-connect-mysql-db_hd.mp4" length="70784000" type="video/mp4" />

		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>

		<media:group>
			<media:content url="http://videos.videopress.com/ViKkCJGn/ruby-script-connect-mysql-db_hd.mp4" fileSize="70784000" type="video/mp4" medium="video" bitrate="3160" isDefault="true" duration="175" width="1280" height="720" />

			<media:content url="http://videos.videopress.com/ViKkCJGn/ruby-script-connect-mysql-db_dvd.mp4" fileSize="34227200" type="video/mp4" medium="video" bitrate="1528" isDefault="false" duration="175" width="640" height="360" />

			<media:content url="http://videos.videopress.com/ViKkCJGn/ruby-script-connect-mysql-db_std.mp4" fileSize="17830400" type="video/mp4" medium="video" bitrate="796" isDefault="false" duration="175" width="400" height="224" />

			<media:content url="http://videos.videopress.com/ViKkCJGn/ruby-script-connect-mysql-db_fmt1.ogv" fileSize="17830400" type="video/ogg" medium="video" bitrate="796" isDefault="false" duration="175" width="400" height="224" />

			<media:rating scheme="urn:mpaa">g</media:rating>
			<media:title type="plain">Using a Ruby Script to Connect to MySQL Database</media:title>
			<media:description type="plain">This screencast will show you how to connect to a MySQL database using a Ruby script.</media:description>
			<media:thumbnail url="http://videos.videopress.com/ViKkCJGn/ruby-script-connect-mysql-db_std.original.jpg" width="256" height="144" />
			<media:player url="http://s0.videopress.com/player.swf?v=1.03&#038;guid=ViKkCJGn&#038;isDynamicSeeking=true" width="400" height="225" />
		</media:group>
	</item>
		<item>
		<title>Ruby on Rails Tutorials and Videocasts</title>
		<link>http://dyba.wordpress.com/2010/02/28/ruby-on-rails-tutorials-and-videocasts/</link>
		<comments>http://dyba.wordpress.com/2010/02/28/ruby-on-rails-tutorials-and-videocasts/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 06:51:22 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=26</guid>
		<description><![CDATA[I finally found the programming language I want to dedicate myself to learn: Ruby. Since August of 2009, I have hacked away at making sense of the Ruby language. I have read a lot of books, used the Ruby console, and written small-scale Ruby on Rails applications. I am ready for the next step. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=26&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I finally found the programming language I want to dedicate myself to learn: Ruby. Since August of 2009, I have hacked away at making sense of the Ruby language. I have read a lot of books, used the Ruby console, and written small-scale Ruby on Rails applications. I am ready for the next step. I am going to blog about Ruby and Ruby on Rails. I know there are a lot of people out there banging their head on the screen. “How can I make this work?!” This blog will serve as a two way street. It will help people find answers to their problems, and it will build up my knowledge of Ruby and help me become a better writer. It is now time that I ask you, fellow Ruby developer, to offer problems you’d like to see solved. I would be more than happy to take your suggestions. Email me at [ dyba (dot) ruby (at) gmail (dot) com ]. I’ve only been programming in Ruby for now seven months. I consider myself an intermediate Ruby developer. I have not yet launched a site built on Ruby on Rails, but I do have plans for that in the future. I haven’t had any formal training yet. With that said, I know I still have gaps in my understanding of the language and may not be able to every question. The kind of entries I’d like to post will:</p>
<ul>
<li>Be      easy to read</li>
<li>Use      video for explanation</li>
<li>Provide      sample code</li>
</ul>
<p>I don’t know how frequently I plan to post entries. I will start with a weekly post and see how well I can manage that. In the end, the goal is to become a Ruby on Rails master.</p>
<p><img class="aligncenter" title="Ruby on Rails Master" src="http://www.itexto.net/devkico/wp-content/uploads/2009/03/bruce_on_rails.jpg" alt="" width="411" height="304" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=26&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2010/02/28/ruby-on-rails-tutorials-and-videocasts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>

		<media:content url="http://www.itexto.net/devkico/wp-content/uploads/2009/03/bruce_on_rails.jpg" medium="image">
			<media:title type="html">Ruby on Rails Master</media:title>
		</media:content>
	</item>
		<item>
		<title>Developing C programs on Mac OS X using Xcode 3.0</title>
		<link>http://dyba.wordpress.com/2008/04/13/developing-c-programs-on-mac-os-x-using-xcode-30/</link>
		<comments>http://dyba.wordpress.com/2008/04/13/developing-c-programs-on-mac-os-x-using-xcode-30/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 05:34:52 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=20</guid>
		<description><![CDATA[Having switched to a Mac a few months ago, I was interested in finding out how to program in C using the software available on my Mac. Xcode 3.0 does the job. If you want to write a C program, just follow along: Open Xcode 3.0 and click File &#62; New Project. Select the arrow [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=20&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Having switched to a Mac a few months ago, I was interested in finding out how to program in C using the software available on my Mac.  Xcode 3.0 does the job.  If you want to write a C program, just follow along:</p>
<p>Open Xcode 3.0 and click File &gt; New Project.  Select the arrow next to “Command Line Utility” and choose Standard Tool.  Give your project a name and a location in which to store all the files that Xcode will build for you.</p>
<p><a href="http://dyba.files.wordpress.com/2008/04/buildcprogramnewproject.jpg"><img class="alignnone size-medium wp-image-24" src="http://dyba.files.wordpress.com/2008/04/buildcprogramnewproject.jpg?w=448&#038;h=468" alt="" width="448" height="468" /></a></p>
<p>Now select Window &gt; Organizer.  Next, you’ll want to open a finder window and browse for the location of the name of the project folder you created earlier.  Drag and drop that folder into the Organizer window.  You’ll notice that it shows up there.</p>
<p><a href="http://dyba.files.wordpress.com/2008/04/cprogramorganizer.jpg"><img class="alignnone size-medium wp-image-23" src="http://dyba.files.wordpress.com/2008/04/cprogramorganizer.jpg?w=218&#038;h=703" alt="" width="218" height="703" /></a></p>
<p>Click the arrow next to the project folder to see the files inside this folder.  Next, to access the main C file, you can double click the file main.c, or you can click on the bottom icon the furthest to the right to open the editor in the Organizer window.</p>
<p><a href="http://dyba.files.wordpress.com/2008/04/editorinorganizercprogram.jpg"><img class="alignnone size-medium wp-image-22" src="http://dyba.files.wordpress.com/2008/04/editorinorganizercprogram.jpg?w=450&#038;h=317" alt="" width="450" height="317" /></a></p>
<p>The next thing you&#8217;ll want to do is click the Build button, the one with the hammer.  Finally, click the Run button.  There you have it: you&#8217;re first C program on a Mac.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dyba.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dyba.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=20&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2008/04/13/developing-c-programs-on-mac-os-x-using-xcode-30/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>

		<media:content url="http://dyba.files.wordpress.com/2008/04/buildcprogramnewproject.jpg" medium="image" />

		<media:content url="http://dyba.files.wordpress.com/2008/04/cprogramorganizer.jpg" medium="image" />

		<media:content url="http://dyba.files.wordpress.com/2008/04/editorinorganizercprogram.jpg?w=450" medium="image" />
	</item>
		<item>
		<title>Edge Detection Simulation</title>
		<link>http://dyba.wordpress.com/2008/04/06/edge-detection-simulation/</link>
		<comments>http://dyba.wordpress.com/2008/04/06/edge-detection-simulation/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 06:18:45 +0000</pubDate>
		<dc:creator>danieldyba</dc:creator>
				<category><![CDATA[MATLAB]]></category>

		<guid isPermaLink="false">http://dyba.wordpress.com/?p=9</guid>
		<description><![CDATA[The following example demonstrates edge detection on a black and white image. I wrote the code in MATLAB. clear; clc; % Define kernel parameters sigma = 4; size = 4; % Initialize dimensions of kernel matrix xKerMax = 3; yKerMax = 3; % Initialize dimensions of source image yMax = 326; xMax = 640; % [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=9&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following example demonstrates edge detection on a black and white image.  I wrote the code in MATLAB.</p>
<p>clear;<br />
clc;</p>
<p><span style="color:green;">% Define kernel parameters</span><br />
sigma = 4;<br />
size = 4;</p>
<p><span style="color:green;">% Initialize dimensions of kernel matrix</span><br />
xKerMax = 3;<br />
yKerMax = 3;</p>
<p><span style="color:green;">% Initialize dimensions of source image</span><br />
yMax = 326;<br />
xMax = 640;</p>
<p><span style="color:green;">% Initialize the kernel matrix</span><br />
kernel = zeros(3, 3);</p>
<p><span style="color:green;">% Initialize the destination image</span><br />
dstImg = zeros(yMax &#8211; (yKerMax &#8211; 1),xMax &#8211; (xKerMax &#8211; 1));</p>
<p><span style="color:green;">% Compute elements of kernel matrix</span><br />
<span style="color:blue;">for</span> yKer = 1:yKerMax<br />
<span style="color:blue;">for</span> xKer = 1:xKerMax<br />
<span style="color:blue;">if</span>( mod((yKer &#8211; 1)*yKerMax + xKer, 2) == 0)<br />
kernel(yKer, xKer) = -1;<br />
<span style="color:blue;">else</span><br />
kernel(yKer, xKer) = 0;<br />
<span style="color:blue;">end</span><br />
<span style="color:blue;">if</span>( (yKer &#8211; 1)*yKerMax + xKer == 5)<br />
kernel(yKer,xKer) = sigma;<br />
<span style="color:blue;">end</span><br />
<span style="color:blue;">end</span><br />
<span style="color:blue;">end</span></p>
<p><span style="color:green;">% Plot kernel</span><br />
<span style="color:green;">%figure(3),surf(xKer,yKer,kernel);</span></p>
<p><span style="color:green;">% Load the source Image</span><br />
srcImg = imread(<span style="color:purple;">&#8216;bw.jpg&#8217;</span>);</p>
<p><span style="color:green;">% Convert data in image to double</span><br />
srcImg = im2double(srcImg);</p>
<p><span style="color:green;">% Plot the data in source image</span><br />
figure(1), imshow(srcImg);</p>
<p><span style="color:green;">% Carry out convolution</span><br />
<span style="color:blue;">for</span> y = 1:(yMax &#8211; (yKerMax &#8211; 1))<br />
<span style="color:blue;">for</span> x = 1:(xMax &#8211; (xKerMax &#8211; 1))<br />
<span style="color:blue;">for</span> yKer = 1:yKerMax<br />
<span style="color:blue;">for</span> xKer = 1:xKerMax<br />
dstImg(y,x) = dstImg(y,x) + srcImg(y + yKer &#8211; 1, x + xKer &#8211; 1)*kernel(yKer, xKer);<br />
<span style="color:blue;">end</span><br />
<span style="color:blue;">end</span><br />
<span style="color:blue;">end</span><br />
<span style="color:blue;">end</span></p>
<p>dstImg = im2uint8(dstImg);</p>
<p>figure(2), imshow(dstImg);</p>
<p><a href="http://dyba.files.wordpress.com/2008/04/bw.jpg"><img class="aligncenter size-medium wp-image-13" src="http://dyba.files.wordpress.com/2008/04/bw.jpg?w=600" alt="The source image before filtering" /></a></p>
<p><a href="http://dyba.files.wordpress.com/2008/04/bw_filt.jpg"><img class="aligncenter size-full wp-image-19" src="http://dyba.files.wordpress.com/2008/04/bw_filt.jpg?w=450" alt="The filtered image" width="640" height="325" /></a><a href="http://dyba.files.wordpress.com/2008/04/bw_filtered.jpg"> </a></p>
<p>By altering the part of the code involving the convolution, we can create a binary image that may give us a clearer picture of the outlines of the image.  The change is as follows:</p>
<p><span style="color:green;">% Carry out convolution</span><br />
<span style="color:blue;">for</span> y = 1:(yMax &#8211; (yKerMax &#8211; 1))<br />
<span style="color:blue;">for</span> x = 1:(xMax &#8211; (xKerMax &#8211; 1))<br />
<span style="color:blue;">for</span> yKer = 1:yKerMax<br />
<span style="color:blue;">for</span> xKer = 1:xKerMax<br />
dstImg(y,x) = dstImg(y,x) + srcImg(y + yKer &#8211; 1, x + xKer &#8211; 1)*kernel(yKer, xKer);<br />
<span style="color:blue;">end</span><br />
<span style="color:blue;">end</span><br />
<span style="color:blue;"> if</span> (dstImg(y,x) &lt;= 0)<br />
dstImg(y,x) = 0;<br />
<span style="color:blue;"> else</span><br />
dstImg(y,x) = 1;<br />
<span style="color:blue;"> end</span><br />
<span style="color:blue;">end</span><br />
<span style="color:blue;">end</span></p>
<p>This yields the following binary image:</p>
<p><a href="http://dyba.files.wordpress.com/2008/04/bw_binary.jpg"><img class="aligncenter size-full wp-image-17" src="http://dyba.files.wordpress.com/2008/04/bw_binary.jpg?w=450" alt="The binary image" width="630" height="320" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dyba.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dyba.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyba.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyba.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyba.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyba.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyba.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyba.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyba.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyba.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyba.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyba.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyba.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyba.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyba.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyba.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyba.wordpress.com&amp;blog=3123294&amp;post=9&amp;subd=dyba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyba.wordpress.com/2008/04/06/edge-detection-simulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1237fa7ee270ace2ebb53c8cab91a6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">danieldyba</media:title>
		</media:content>

		<media:content url="http://dyba.files.wordpress.com/2008/04/bw.jpg" medium="image">
			<media:title type="html">The source image before filtering</media:title>
		</media:content>

		<media:content url="http://dyba.files.wordpress.com/2008/04/bw_filt.jpg?w=450" medium="image">
			<media:title type="html">The filtered image</media:title>
		</media:content>

		<media:content url="http://dyba.files.wordpress.com/2008/04/bw_binary.jpg?w=450" medium="image">
			<media:title type="html">The binary image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
