<?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>Greg Moreno &#187; ruby</title>
	<atom:link href="http://gregmoreno.wordpress.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://gregmoreno.wordpress.com</link>
	<description>think BIG, act small</description>
	<lastBuildDate>Fri, 10 Feb 2012 22:36:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gregmoreno.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Greg Moreno &#187; ruby</title>
		<link>http://gregmoreno.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://gregmoreno.wordpress.com/osd.xml" title="Greg Moreno" />
	<atom:link rel='hub' href='http://gregmoreno.wordpress.com/?pushpress=hub'/>
		<item>
		<title>24 Ruby tips and tricks</title>
		<link>http://gregmoreno.wordpress.com/2012/02/09/24-ruby-language-tips-and-tricks/</link>
		<comments>http://gregmoreno.wordpress.com/2012/02/09/24-ruby-language-tips-and-tricks/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 01:35:44 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=480</guid>
		<description><![CDATA[Peter Cooper will share more tips in his book to be released later this year. Stay tune and don&#8217;t forget to leave your email address to get updates at http://rubyreloaded.com/trickshots/ Here are some of the tips in the video. Generate random numbers within a given range Dump your object using awesome_print Concatenating strings Include modules [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=480&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><iframe width="497" height="280" src="http://www.youtube.com/embed/gIEMKOI_Y-4?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>Peter Cooper will share more tips in his book to be released later this year. Stay tune and don&#8217;t forget to leave your email address to get updates at <a href="http://rubyreloaded.com/trickshots/">http://rubyreloaded.com/trickshots/</a></p>
<p>Here are some of the tips in the video.</p>
<p><strong>Generate random numbers within a given range</strong></p>
<p><pre class="brush: ruby;">
irb(main):019:0&gt; rand(10..20)
=&gt; 12
irb(main):020:0&gt; rand(10...20) # works with exclusive range
=&gt; 16
</pre></p>
<p><strong>Dump your object using awesome_print</strong><br />
<pre class="brush: ruby;">
# Install the gem first
gem install awesome_print

irb(main):001:0&gt; require 'ap'
=&gt; true
irb(main):002:0&gt; ap :a =&gt; 1, :b =&gt; 'greg', :c =&gt; [1,2,3]
{
    :a =&gt; 1,
    :b =&gt; &quot;greg&quot;,
    :c =&gt; [
        [0] 1,
        [1] 2,
        [2] 3
    ]
}
=&gt; {:a=&gt;1, :b=&gt;&quot;greg&quot;, :c=&gt;[1, 2, 3]}

</pre></p>
<p><strong>Concatenating strings</strong></p>
<p><pre class="brush: ruby;">
irb(main):005:0&gt; &quot;abc&quot; + &quot;def&quot;
=&gt; &quot;abcdef&quot;
irb(main):006:0&gt; &quot;abc&quot;.concat(&quot;def&quot;)
=&gt; &quot;abcdef&quot;
irb(main):007:0&gt; x = &quot;abc&quot; &quot;def&quot;
=&gt; &quot;abcdef&quot;
</pre></p>
<p><strong>Include modules in a single line</strong></p>
<p><pre class="brush: ruby;">
class MyClass
  include Module1, Module2, Module3
  # However, the modules are included in reverse order. Confusing eh!
end
</pre></p>
<p><strong>Instance variable interpolation</strong></p>
<p><pre class="brush: ruby;">
irb(main):008:0&gt; @name = &quot;greg&quot;
=&gt; &quot;greg&quot;
irb(main):009:0&gt; &quot;my name is #{@name}&quot;
=&gt; &quot;my name is greg&quot;
irb(main):010:0&gt; &quot;my name is #@name&quot;
=&gt; &quot;my name is greg&quot;
</pre></p>
<p>I still prefer the use curly braces.</p>
<p><strong>Syntax checking</strong><br />
<pre class="brush: ruby;">
➜  ruby -c facu.rb 
facu.rb:12: syntax error, unexpected keyword_end, expecting $end
</pre></p>
<p><strong>Zipping arrays</strong><br />
<pre class="brush: ruby;">
irb(main):027:0&gt; names = %w(fred jess john)
=&gt; [&quot;fred&quot;, &quot;jess&quot;, &quot;john&quot;]
irb(main):028:0&gt; ages = [38, 47,91]
=&gt; [38, 47, 91]
irb(main):029:0&gt; locations = %w(spain france usa)
=&gt; [&quot;spain&quot;, &quot;france&quot;, &quot;usa&quot;]
irb(main):030:0&gt; names.zip(ages)
=&gt; [[&quot;fred&quot;, 38], [&quot;jess&quot;, 47], [&quot;john&quot;, 91]]
irb(main):031:0&gt; names.zip(ages, locations)
=&gt; [[&quot;fred&quot;, 38, &quot;spain&quot;], [&quot;jess&quot;, 47, &quot;france&quot;], [&quot;john&quot;, 91, &quot;usa&quot;]]
</pre></p>
<p><strong>Range into arrays</strong></p>
<p><pre class="brush: ruby;">
irb(main):034:0&gt; (10..20).to_a  # what I used to do
=&gt; [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
irb(main):035:0&gt; [*10..20]
=&gt; [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
</pre></p>
<p><strong>Using parameter as default value</strong><br />
<pre class="brush: ruby;">
irb(main):047:0&gt; def method(a, b=a); &quot;#{a} #{b}&quot;; end
=&gt; nil
irb(main):048:0&gt; method 1
=&gt; &quot;1 1&quot;
irb(main):049:0&gt; method 1, 2
=&gt; &quot;1 2&quot;
</pre></p>
<p><strong>Put regex match in a variable</strong><br />
<pre class="brush: ruby;">
irb(main):058:0&gt; s = &quot;Greg Moreno&quot;
=&gt; &quot;Greg Moreno&quot;
irb(main):059:0&gt; /(?&lt;first&gt;\w+) (?&lt;second&gt;\w+)/ =~ s
=&gt; 0
irb(main):060:0&gt; first
=&gt; &quot;Greg&quot;
irb(main):061:0&gt; second
=&gt; &quot;Moreno&quot;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/480/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=480&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2012/02/09/24-ruby-language-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby 101: method_missing gotchas</title>
		<link>http://gregmoreno.wordpress.com/2011/05/06/ruby-101-method_missing-gotchas/</link>
		<comments>http://gregmoreno.wordpress.com/2011/05/06/ruby-101-method_missing-gotchas/#comments</comments>
		<pubDate>Fri, 06 May 2011 02:21:37 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=406</guid>
		<description><![CDATA[Forgetting &#8216;super&#8217; with &#8216;method_missing&#8217; method_missing is a hallmark of Ruby metaprogramming. It is one of those coding techniques that you need to master if you want to move from white belt to black belt. Aside from that, it is also fun to use. It works but you want explicit methods for each format. So you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=406&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  <strong>Forgetting &#8216;super&#8217; with &#8216;method_missing&#8217;</strong></p>
<p>  method_missing is a hallmark of Ruby metaprogramming. It is one of those coding techniques that you need to master if you want to move from white belt to black belt. Aside from that, it is also fun to use.</p>
<p><pre class="brush: ruby;">
  class RadioActive
    def initialize(path)
      ...
    end

    def to_format(format)
      ...
    end
  end
  
  
  d = RadioActive.new('/path/to/uranium')
  d.to_format('xml')
</pre></p>
<p>  It works but you want explicit methods for each format. So you tap into your Ruby skills and implement your own method_missing. </p>
<p><pre class="brush: ruby;">
  class RadioActive
    def method_missing(name, *args)
      if name.to_s =~ /^to_(\w+)$/
        to_format($1)
      end
    end
  end
  
  
  d = RadioActive.new('/path/to/uranium')
  d.to_xml            # WORKS
  d.to_format('xml')  # WORKS
  d.undefined_method  # FAILS
</pre></p>
<p>  Unfortunately, the last call to &#8216;undefined_method&#8217; fails. Actually, you would not know it fails because Ruby will not fire any exception. In case there is an undefined method, let us see how Ruby handles it.</p>
<p><pre class="brush: ruby;">
  &gt;&gt; s = 'uranium'
   =&gt; &quot;uranium&quot; 
  &gt;&gt; s.to_xml
  NoMethodError: undefined method `to_xml' for &quot;uranium&quot;:String
</pre></p>
<p>  There you go. But there is no need to raise the &#8216;NoMethodError&#8217; in your code. Instead, simply call &#8216;super&#8217; if you are not handling the method. Whether you have your own class or inheriting from another, do not forget to call &#8216;super&#8217; with your &#8216;method_missing&#8217; </p>
<p><pre class="brush: ruby;">
  class RadioActive
    def method_missing(name, *args)
      if name.to_s =~ /^to_(\w+)$/
        to_format($1)
      else
        super
      end
    end
  end
  
  d = RadioActive.new('/path/to/uranium')
  d.undefined_method
  # =&gt; in `method_missing': undefined method `undefined_method' for # (NoMethodError)
</pre></p>
<p>  Calling &#8216;super&#8217; is not just for &#8216;missing_method&#8217;. You also need to do the same for the other hook methods like &#8216;const_missing&#8217;, &#8216;append_features&#8217;, &#8216;method_added&#8217;.</p>
<p>  <strong>Forgetting respond_to?</strong></p>
<p>  If you modify &#8216;method_missing&#8217;, it will also affect the behavior of &#8216;respond_to?&#8217; because what you are adding in as methods do not actually exist &mdash; they are ghost methods. If you check the list of instance methods for our class, it will only show 2.</p>
<p> <pre class="brush: ruby;">
  &gt;&gt; RadioActive.instance_methods(false)
  =&gt; [&quot;method_missing&quot;, &quot;to_format&quot;]
 
  &gt;&gt; d.respond_to?('to_format')
  =&gt; true
  &gt;&gt; d.respond_to?('to_xml')
  =&gt; false
  </pre></p>
<p>  Every time you modify &#8216;method_missing&#8217;, you also need to update &#8216;respond_to?&#8217;</p>
<p>  <pre class="brush: ruby;">
  class RadioActive
    def respond_to?(name)
      !!(name.to_s =~ /^to_/ || super)
    end
  end
  </pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=406&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2011/05/06/ruby-101-method_missing-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby 101: Improving your code by defining methods dynamically</title>
		<link>http://gregmoreno.wordpress.com/2011/01/03/ruby-101-improving-your-code-by-defining-methods-dynamically/</link>
		<comments>http://gregmoreno.wordpress.com/2011/01/03/ruby-101-improving-your-code-by-defining-methods-dynamically/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 02:39:06 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=424</guid>
		<description><![CDATA[Let&#8217;s say you have a user and you want to check its role. class User attr_accessor :role end u = User.new u.role = 'admin' # somewhere in your code you check the role if u.role == 'admin' puts 'admin' elsif u.role == 'moderator' puts 'moderator' elsif u.role == 'guest' puts 'guest' end Using a string [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=424&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  Let&#8217;s say you have a user and you want to check its role.</p>
<pre class="brush: ruby">

  class User
    attr_accessor :role
  end

  u = User.new
  u.role = 'admin'

  # somewhere in your code you check the role

  if u.role == 'admin'
    puts 'admin'
  elsif u.role == 'moderator'
    puts 'moderator'
  elsif u.role == 'guest'
    puts 'guest'
  end
</pre>
<p>  Using a string value is bad code and you can improve this by using constants instead. But still, this is bad code becauses it exposes implementation details of your User class.</p>
<p>  For our first improvement, we define methods that check the user&#8217;s role and hide the implementation of the role checking inside the User class.</p>
<pre class="brush: ruby">

  class User

    attr_accessor :role

    def is_admin?
      self.role == 'admin'
    end

    def is_moderator?
      self.role == 'moderator'
    end

    def is_guest?
      self.role == 'guest'
    end

  end

  u = User.new
  u.role = 'guest'

  if u.is_admin?
    puts 'admin'
  elsif u.is_moderator?
    puts 'moderator'
  elsif u.is_guest?
    puts 'guest'
  end
</pre>
<p>  Our first improvement is definitely better than the original but there are duplicate code in the role checking. You can eliminate the duplicate code by delegating the role checking to a single method.</p>
<pre class="brush: ruby">
  class User

    attr_accessor :role

    def is_admin?
      is_role? 'admin'
    end

    def is_moderator?
      is_role? 'moderator'
    end

    def is_guest?
      is_role? 'guest'
    end

  protected

    def is_role?(name)
      self.role == name
    end

  end
</pre>
<p>  Our second improvement is a classic refactoring technique and common in any modern programming language. In other words, there is nothing &#8220;Ruby&#8221; about it. Before you get bored, I will now show the Ruby version.</p>
<p>  The Ruby version uses &#8216;define_method()&#8217; to further eliminate duplicate code. </p>
<pre class="brush: ruby">

  class User

    attr_accessor :role

    def self.has_role(name)
      define_method("is_#{name}?") do
        self.role == "#{name}"
      end
    end

    has_role :admin
    has_role :moderator
    has_role :guest

  end
</pre>
<p>  By using &#8216;define_method()&#8217;, we were able to add instance methods to our class User. You can check the new instance methods via irb.</p>
<pre class="brush: ruby">

  ruby-1.9.2-p0 &gt; User.instance_methods.grep /^is/
  =&gt; [:is_admin?, :is_moderator?, :is_guest?, :is_a?] 
</pre>
<p>  Note that &#8216;has_role()&#8217; is just another method and as such you can modify it to accept several parameters, an array, or other class. For example, we can make &#8216;has_role&#8217; accept a list of roles.</p>
<pre class="brush: ruby">
  class User

    attr_accessor :role

    def self.has_roles(*names)
      names.each do |name|
        define_method("is_#{name}?") do
          self.role == "#{name}"
        end
      end
    end

    has_roles :admin, :moderator, :guest

  end
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/424/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=424&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2011/01/03/ruby-101-improving-your-code-by-defining-methods-dynamically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use OpenAmplify with Ruby</title>
		<link>http://gregmoreno.wordpress.com/2010/10/06/how-to-use-openamplify-with-ruby/</link>
		<comments>http://gregmoreno.wordpress.com/2010/10/06/how-to-use-openamplify-with-ruby/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 02:41:45 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=428</guid>
		<description><![CDATA[The OpenAmplify API reads text you supply and returns linguistic data explaining and classifying the content. What you do with that analysis is, in the fine tradition of APIs and mashups, up to you. Some possibilities might include pairing ads with articles, creating rich tag-clouds, or monitoring the tone of forum threads. I created a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=428&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  The <a href="http://community.openamplify.com/blogs/quickstart/pages/overview.aspx">OpenAmplify API</a> reads text you supply and returns linguistic data explaining and classifying the content. What you do with that analysis is, in the fine tradition of APIs and mashups, up to you. Some possibilities might include pairing ads with articles, creating rich tag-clouds, or monitoring the tone of forum threads.</p>
<p>  I created a ruby gem to simplify the use of the OpenAmplify API. It&#8217;s still in the early stages but should be enough to get you started.</p>
<p>  <strong>Output Format</strong></p>
<p>  In case you need a different format, OpenAmplify supports XML, JSON, RDF, CSV. It can also return the result as a fancy HTML page.</p>
<p>  The source code is available in github: <a href="http://github.com/gregmoreno/openamplify">http://github.com/gregmoreno/openamplify</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/428/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=428&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2010/10/06/how-to-use-openamplify-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Using RabbitMQ and AMQP with Ruby</title>
		<link>http://gregmoreno.wordpress.com/2010/09/28/using-rabbitmq-and-amqp-with-ruby/</link>
		<comments>http://gregmoreno.wordpress.com/2010/09/28/using-rabbitmq-and-amqp-with-ruby/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 02:43:39 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[rabbitmq]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=431</guid>
		<description><![CDATA[AMQP stands for Advanced Message Queuing Protocol. RabbitMQ is a server that implements the protocol. RabbitMQ is available on Linux, OSX, and Windows. Installation instructions for RabbitMQ are available at http://www.rabbitmq.com/install.html I will be running RabbitMQ on Ubuntu 9.10. First, let&#8217;s install the server: Next, we install the amqp gem by Aman Gupta. The gem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=431&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  <a href="http://www.amqp.org/">AMQP</a> stands for Advanced Message Queuing Protocol. RabbitMQ is a server that implements the protocol. RabbitMQ is available on Linux, OSX, and Windows. Installation instructions for RabbitMQ are available at <a href="http://www.rabbitmq.com/install.html">http://www.rabbitmq.com/install.html</a></p>
<p>  I will be running RabbitMQ on Ubuntu 9.10. First, let&#8217;s install the server:</p>
<p>  Next, we install the amqp gem by Aman Gupta. The gem can also be found at <a href="http://github.com/tmm1/amqp">http://github.com/tmm1/amqp</a></p>
<p>  Let&#8217;s now build a simple publisher code. Note the difference in the gem&#8217;s name and the file you need to use the gem.</p>
<p>  All queues are created automatically the first time it is accessed. Make sure this is the same queue our consumers will use.</p>
<p>  Next, the consumer code:</p>
<p>  The &#8216;subscribe&#8217; method registers with the queue telling it to call the block when a message has arrived. Alternatively, you can use &#8216;pop&#8217; but this would constantly poll the server for new messages making unnecessary calls even if the queue is empty.</p>
<p>  If you want to run AMQP on several machines, just specify the location of the broker in your publisher and consumer code:</p>
<p>  You only need to run 1 rabbitmq server, which in my case is on Ubuntu. When you try the code in other machines, you only need the <a href="http://github.com/tmm1/amqp">amqp</a> gem installed.</p>
<p>  I highly recommend <a href="http://tinyurl.com/2aqcz22">Distributed Programming with Ruby</a> by Mark Bates if you&#8217;re interested in distributed programming.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/431/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=431&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2010/09/28/using-rabbitmq-and-amqp-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Deploy a Rails 3, Sqlite3 application in Tomcat using JRuby</title>
		<link>http://gregmoreno.wordpress.com/2010/09/01/deploy-a-rails-3-sqlite3-application-in-tomcat-using-jruby/</link>
		<comments>http://gregmoreno.wordpress.com/2010/09/01/deploy-a-rails-3-sqlite3-application-in-tomcat-using-jruby/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 02:45:03 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=435</guid>
		<description><![CDATA[and have a Ruby version running side-by-side. A few months ago I got interested in JRuby while researching for text mining algorithms. I found some gems but they are either unmaintained or inadequate while the mature libraries I found were written in Java. No problem! JRuby to the rescue. Thank God. Next stop, I decided [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=435&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  <em>and have a Ruby version running side-by-side.</em></p>
<p>  A few months ago I got interested in <a href="http://jruby.org/">JRuby</a> while researching for <a href="http://alias-i.com/lingpipe/">text mining algorithms</a>. I found some gems but they are either unmaintained or inadequate while the mature libraries I found were written in Java. No problem! JRuby to the rescue. Thank God.</p>
<p>  Next stop, I decided to take Rails 3 and JRuby for a spin. Incidentally, I will be on a <a href="http://railsjam.net">3-city Rails tour in the Philippines</a> this September  and since there are many<a href="http://tech.groups.yahoo.com/group/pinoyjug/"> Filipino Java developers</a>, they might find it interesting to see their favorite Java platform works nicely with Ruby on Rails.</p>
<p>  <strong>Setup</strong></p>
<p>  I will be using the following for this tutorial:</p>
<p>  java 1.6 + JDK<br />
  tomcat 7.0.2<br />
  rvm 1.0.1<br />
  jruby 1.5.0<br />
  ruby 1.9.2p0</p>
<p>  Further below, I outline how to install these software. First, let’s see my current environment.</p>
<p>  <pre class="brush: bash;">
  $ more /etc/issue
  Ubuntu 9.10 \n \l
  
  $ java -version
  java version &amp;quot;1.6.0_20&amp;quot;
  Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
  Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)
  
  $ rvm -v
  rvm 1.0.1 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]
  
  $ jruby -v
  jruby 1.5.0 (ruby 1.8.7 patchlevel 249) (2010-05-12 6769999) (Java HotSpot(TM) Client VM 1.6.0_20) [i386-java]
  
  $ TOMCAT/bin/version.sh 
  Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.2
  Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.2
  Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.2/temp
  Using JRE_HOME:        /usr
  Using CLASSPATH:       /usr/local/apache-tomcat-7.0.2/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.2/bin/tomcat-juli.jar
  Server version: Apache Tomcat/7.0.2
  Server built:   Aug 4 2010 12:23:47
  Server number:  7.0.2.0
  OS Name:        Linux
  OS Version:     2.6.31-22-generic
  Architecture:   i386
  JVM Version:    1.6.0_20-b02
  JVM Vendor:     Sun Microsystems Inc.
  
  $ ruby -v
  ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
  
  # install jdk and tomcat
  
  $ aptitude install curl sun-java6-bin sun-java6-jre sun-java6-jdk
  $ wget  http://apache.mobiles5.com/tomcat/tomcat-7/v7.0.2-beta/bin/apache-tomcat-7.0.2.tar.gz
  $ tar zxvf apache-tomcat-7.0.2.tar.gz
  $ mv apache-tomcat-7.0.2 /usr/local
  
</pre></p>
<p>  Of course, these assume you want to use 7.0.2 and you want it installed at your /usr/local.</p>
<p>  <strong>Install JRuby, Rails 3</strong></p>
<p>  I assume you already have <a href="http://rvm.beginrescueend.com/">rvm</a> installed. If not, I highly recommend that you do. I can’t imagine a Ruby developer not using rvm <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>  <pre class="brush: bash;">
  $ rvm install jruby
  $ rvm jruby
  $ rvm gemset create railsjam
  $ rvm jruby@railsjam
  $ gem install rails
</pre></p>
<p>  <strong>Try a sample app</strong></p>
<p>  I’ve created  sample app for the<a href="http://railsjam.net"> RailsJam tour</a>. This have several functionalities already and better than creating a Rails app from scratch.</p>
<p>  $ git clone git://github.com/gregmoreno/railsjam.git</p>
<p>  <strong>Update the Gemfile</strong></p>
<p>  You need a separate set of gems to make your Rails 3 application work with JRuby. For learning purposes, I want my Rails 3 application to work other than JRuby. To accomplish that, we need to specify what gems are needed solely by JRuby.</p>
<p>  <pre class="brush: bash;">
  source 'http://rubygems.org'
  
  gem 'rails', '3.0.0'
  
  if defined?(JRUBY_VERSION)
    gem 'jdbc-sqlite3'
    gem 'activerecord-jdbc-adapter'
    gem 'activerecord-jdbcsqlite3-adapter'
    gem 'jruby-openssl'
    gem 'jruby-rack'
    gem 'warbler'
  else
    gem 'sqlite3-ruby', :require =&gt; 'sqlite3'
  end
</pre></p>
<p>  (A copy of this Gemfile is available at the ‘jruby’ folder of the railsjam application.)</p>
<p>  Now, it’s time to intall the gems. You must delete &#8216;Gemfile.lock&#8217;. Otherwise,  bundle picks up wrong version of jdbc</p>
<p>  <pre class="brush: bash;">
  $ rm Gemfile.lock  
  $ jruby -S bundle install
</pre></p>
<p>  <strong>Prepare the database.</strong></p>
<p>  The first time I worked on this tutorial, I needed to specify the jdbcsqlite3 as the database adapter. However, when I tried the tutorial on the same machine with a fresh gemset, it worked pretty well with just ‘sqlite3’.  Just to be sure, I modified  ‘database.yml’ to check for JRuby.</p>
<p>  <pre class="brush: bash;">
  development:
    adapter: &lt;%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %&gt;
    database: db/development.sqlite3
    pool: 5
    timeout: 5000
  
  production:
    adapter: &lt;%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %&gt;
    database: /home/greg/dev/railsjam/db/development.sqlite3 
    pool: 5
    timeout: 5000
</pre></p>
<p>  When you deploy to Tomcat, it will be on ‘production’ mode by default. Since sqlite3 is file based and for simplicity, I used the same development database.</p>
<p>  Now, do the migration.</p>
<p>  <pre class="brush: bash;">
  $ jruby -S rake db:migrate
</pre></p>
<p>  <strong>Deploy to Tomcat</strong></p>
<p>  We use ‘<a href="http://caldersphere.rubyforge.org/warbler/">warble</a>’ which is an excellent tool for packaging your Rails application. It packages everything you need to run your Rails application inside a Java container.</p>
<p>  <pre class="brush: bash;">
  $ warble
  $ cp railsjam.war  $TOMCAT/webapps
  
  # start Tomcat
  # assuming you arein $TOMCAT dir
  $ sudo ./startup.sh
</pre></p>
<p>  <strong>Check your Rails 3 application</strong></p>
<p>  <pre class="brush: bash;">
  # You should see the famous Rails welcome
  localhost:3000/railsjam
  
  # Play around with your application
  localhost:3000/railsjam/users
</pre></p>
<p>  <strong>Deploy Rails 3 using Ruby 1.9.2 </strong></p>
<p>  Without shutting down your JRuby and Tomcat version, let’s try to run our app using Ruby 1.9.2</p>
<p>  <pre class="brush: bash;">
  # In a new console
  $ rvm 1.9.2
  $ rvm gemset create railsjam
  $ rvm 1.9.2@railsjam
  $ gem install rails
  
  # Assuming you are in the ‘railsjam’ folder
  # This will install sqlite3-ruby gem
  $ bundle install
  
  $ rails server
  
  Now, go play with your Rails 3 applications
  
  # jruby + tomcat
  http://localhost:8080/railsjam/users
  
  # ruby 1.9.2
  http://localhost:3000/users

</pre></p>
<p>  In case you encountered some problems, here are some ways to solve them. If your problem is not listed here, you can email me. I only accept Paypal <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>  <strong>JRuby does not support native extensions</strong></p>
<p>  You did not update the Gemfile to use the jdbc version of sqlite3. You will encounter this error when you install the gems.</p>
<p>  <pre class="brush: bash;">
   
  $ bundle install
  ....
  Installing sqlite3-ruby (1.3.1) with native extensions /home/greg/.rvm/rubies/jruby-1.5.2/lib/ruby/site_ruby/1.8/rubygems/installer.rb:482:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
  
  /home/greg/.rvm/rubies/jruby-1.5.2/bin/jruby extconf.rb 
  WARNING: JRuby does not support native extensions or the `mkmf' library.
           Check http://kenai.com/projects/jruby/pages/Home for alternatives.
  extconf.rb:9: undefined method `dir_config' for main:Object (NoMethodError)
</pre></p>
<p>  <strong>undefined method `attributes_with_quotes&#8217; for class `ActiveRecord::Base&#8217;</strong></p>
<p>  I first encountered this problem when doing migration.</p>
<p>  <pre class="brush: bash;"> 
  $ rake db:migrate
  rake aborted!
  undefined method 'attributes_with_quotes' for class 'ActiveRecord::Base'
</pre></p>
<p>  This is caused by an old version of your jdbc gems. In my case, sometimes bundler installs the old versions:</p>
<p>  <pre class="brush: bash;">
  Installing activerecord-jdbc-adapter (0.9.2) 
  Installing activerecord-jdbcsqlite3-adapter (0.9.2)
</pre></p>
<p>  As of this writing, the latest version is 0.9.7</p>
<p>  <pre class="brush: bash;">
  Installing activerecord-jdbc-adapter-0.9.7-java
  Installing activerecord-jdbcsqlite3-adapter-0.9.7-java
</pre></p>
<p>  <strong>Bundler keeps installing 0.9.2</strong></p>
<p>  <pre class="brush: bash;">
  
  $ rm Gemfile.lock
  $ jruby -S bundle install
</pre></p>
<p>  <strong>no such file to load &#8212; sqlite3</strong></p>
<p>  <pre class="brush: bash;">
  $ rake db:migrate
  (in /home/greg/dev/projects/jruby/railsjam)
  rake aborted!
  no such file to load -- sqlite3
</pre></p>
<p>  &#8216;sqlite3&#8242; is the default name of the database adapter but with jruby, it should be &#8216;jdbcsqlite3&#8242;.<br />
  But, when I tried &#8216;sqlite3&#8242; with a fresh gemset and a new machine, it went well.<br />
  Anyway, just in case you run into the same problem in the future, add a condition<br />
  in your database.yml </p>
<p>  <pre class="brush: bash;">
  development:
    adapter: &lt;%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %&gt;
    database: db/development.sqlite3
    pool: 5
    timeout: 5000
  
  production:
    adapter: &lt;%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %&gt;
    database: /home/greg/dev/railsjam/db/development.sqlite3 
    pool: 5
    timeout: 5000
</pre></p>
<p>  <strong>We&#8217;re sorry, but something went wrong.</strong></p>
<p>  If you see the famous Rails error message, you need to dig in Tomcat’s log files.</p>
<p>  <pre class="brush: bash;">
  $ cd /usr/local/apache-tomcat-7.0.2/logs
  $ ls -al localhost*
  
  -rw-r--r-- 1 root root 1181 2010-09-01 00:17 localhost.2010-09-01.log
  -rw-r--r-- 1 root root 1062 2010-09-01 00:18 localhost_access_log.2010-09-01.txt
  
  $ tail -f localhost.2010-09-01.log 
</pre></p>
<p>  In the log file, you will see the errors like missing database.</p>
<p>  <pre class="brush: bash;">
  org.jruby.rack.RackInitializationException: The driver encountered an error: java.sql.SQLException: path to '/home/greg/dev/tmp/apache-tomcat-7.0.2/webapps/railsjam/WEB-INF/db/production.sqlite3': '/home/greg/dev/tmp/apache-tomcat-7.0.2/webapps/railsjam/WEB-INF/db' does not exist
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/435/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=435&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2010/09/01/deploy-a-rails-3-sqlite3-application-in-tomcat-using-jruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby 101: Make your class behave like a Ruby built-in</title>
		<link>http://gregmoreno.wordpress.com/2010/06/09/ruby-101-make-your-class-behave-like-a-ruby-built-in/</link>
		<comments>http://gregmoreno.wordpress.com/2010/06/09/ruby-101-make-your-class-behave-like-a-ruby-built-in/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 03:35:32 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=452</guid>
		<description><![CDATA[I got re-acquianted with this scenario while working on the OpenAmplify gem &#8211; a wrapper for the OpenAmplify API. When you give the api a text like a blog comment, it will return a list of common terms, opinion scores, named locations, and other information that can be used for text mining operations. The OpenAmplify [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=452&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  I got re-acquianted with this scenario while working on the<a href="http://github.com/gregmoreno/openamplify"> OpenAmplify gem</a> &#8211; a wrapper for the <a href="http://community.openamplify.com/blogs/quickstart/pages/overview.aspx">OpenAmplify API</a>.  When you give the api a text like a blog comment, it will return a list of common terms, opinion scores, named locations, and other information that can be used for text mining operations. </p>
<p>  The OpenAmplify returns key-value pairs in an XML string by default, but it can also be in JSON, CSV, or RDF format. From a Ruby client’s point of view, we want it in Hash.  You can choose to use an XML library like Nokogiri but in my opinion, working with a Hash  fits nicely with Ruby.</p>
<p>  Anyway, back to the problem.  I have an instance variable that holds the data.  One approach is to give clients access to the instance variable.</p>
<p>  <pre class="brush: ruby;">
  class Response
    attr_reader :data
  
    def initialize
      @data = {}
    end
  end
  
  data = response.data
  topics = data[‘Topics’]
</pre></p>
<p>  One major issue with this approach is you’re exposing the internals of your class. What if you decided to rename the variable into ‘@results_in_hash_form’?  Then,  all programs that uses your code will break.  Worse,  you will be limited from enhancing the behavior of your class like lazy loading of the data.  You can wrap the access to your data inside a method but that still presents the problem of exposing the internals of your class. Also, that’s an unnecessary extra line of code <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>  My suggestion is to make &#8216;Response&#8217; behave like a Hash so we can do these:</p>
<p>  <pre class="brush: ruby;">
  topics = response['Topics']
  response.has_key?('Topics')
  
  # And still have our own methods:
  response.some_method_we_defined
</pre></p>
<p>  So, how can we do this? The trick is to delegate the calls to the instance variable. One approach is to define the Hash methods you want to support:</p>
<p>  <pre class="brush: ruby;">
  class Response
  
    [‘[]’, ‘has_key?’, ‘fetch’, ‘empty?’, ‘keys’].each do |method_name|
      class_eval &lt;&lt;-EOS
        def #{method}(*args)
           @data.send(&quot;#{method_name}&quot;, *args)
        end
      EOS
    end
  
  end
</pre></p>
<p>  The code above is a shortcut to writing every method by hand. If you want to support all Hash methods, that would be a lot of typing.  </p>
<p>  A better approach is to just take advantage of Ruby’s ‘method_missing’ which is called every time an undefined method is called.</p>
<p>  <pre class="brush: ruby;">
  class Response
  
    def method_missing(name, *args, &amp;block)
      @data.send(name, *args, &amp;block)
    end
  
  end
</pre></p>
<p>  Of course, how your &#8216;method_missing&#8217; will look like depends on your requirements. In our simple case, we can simply delegate to @data.</p>
<p>  This approach is called a &#8220;Dynamic Proxy&#8221; from the book <a href="http://pragprog.com/titles/ppmetr/metaprogramming-ruby">Metaprogramming Ruby by Paolo Perrota</a>. If you want to take your Ruby skills to the next level, I highly recommend this book.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/452/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=452&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2010/06/09/ruby-101-make-your-class-behave-like-a-ruby-built-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby 101: Hash initialization gotcha</title>
		<link>http://gregmoreno.wordpress.com/2010/05/11/ruby-101-hash-initialization-gotcha/</link>
		<comments>http://gregmoreno.wordpress.com/2010/05/11/ruby-101-hash-initialization-gotcha/#comments</comments>
		<pubDate>Tue, 11 May 2010 03:36:56 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=454</guid>
		<description><![CDATA[I have a code that counts how many times a word occurs &#8211; a perfect fit for Hash. Somewhere, I use the hash returned by the word_counts method to do some calculation. When I run the score, I always get an ‘Infinity’. After some debugging, the problem is this piece of code: ‘word_scores’ returns 0 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=454&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  I have a code that counts how many times a word occurs &#8211; a perfect fit for Hash. </p>
<p>  <pre class="brush: ruby;">
  def word_counts(words)
    counts = Hash.new(0)
    words.each do |word|
      counts[word] += 1
    end
  end
  
  categories = {
    :a =&gt; word_counts(‘some text’)
    :b =&gt; word_counts(‘another set of text’)
  }
</pre></p>
<p>  Somewhere, I use the hash returned by the word_counts method to do some calculation.</p>
<p>  <pre class="brush: ruby;">
  def score(word_scores, words)
    words.each do |word|
      v = word_scores[word]
      v = 0.1 if v.nil?
  
      score += Math.log( v / some_value )
    end
  end
  
  categories.each do |category, word_counts|
    score(word_counts, %w{some random text})
  end
</pre></p>
<p>  When I run the score, I always get an ‘Infinity’.  After some debugging, the problem is this piece of code:</p>
<p>  <pre class="brush: ruby;">
  v = word_scores[word]
  v = 0.1 if v.nil?
</pre></p>
<p>  ‘word_scores’  returns 0 if  ‘word’ doesn’t exist; not nil which is the default behavior. Later, I realized I initialized it via   Hash.new(0) which makes 0 the default value.  In fact, it is not even necessary to check for nil or 0. All we want is to retrieve the value referenced by the key, and if the key does not exist, give me 0.1.</p>
<p>  <pre class="brush: ruby;">
  v = word_counts.fetch word, 0.1
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/454/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=454&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2010/05/11/ruby-101-hash-initialization-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby 101: How to filter an Array using proc</title>
		<link>http://gregmoreno.wordpress.com/2010/04/26/ruby-101-how-to-filter-an-array-using-proc/</link>
		<comments>http://gregmoreno.wordpress.com/2010/04/26/ruby-101-how-to-filter-an-array-using-proc/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 03:40:51 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=459</guid>
		<description><![CDATA[Over at the PhRUG, a Ruby developer community based in the Philippines, we conduct code review sessions via our mailing list. A code is posted and members share alternative implementations. So far, it’s been effective and newbies and veterans alike are learning new things in Ruby. Here’s a recent code that filters an array based [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=459&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  Over at the <a href="http://groups.google.com/group/ruby-phil?hl=en&amp;pli=1">PhRUG</a>,  a Ruby developer community based in the Philippines, we  conduct code review sessions via our mailing list. A code is posted and members share alternative implementations. So far, it’s been effective and newbies and veterans alike are learning new things in Ruby.   Here’s a recent code that filters an array based on several conditions. </p>
<p>  <pre class="brush: ruby;">
  matches = []
  (0..9).each do |i|
   if (i &gt; 5) &amp;&amp; (i % 2).zero? &amp;&amp;  (i % 3).zero?
     matches &lt;&lt; i
   end
  end
</pre></p>
<p>  The first improvement made by Bong is to use ‘select’.</p>
<p>  <pre class="brush: ruby;">
  matches = (0..9).select {|i| (i &gt; 5) &amp;&amp; (i % 2).zero? &amp;&amp;  (i % 3).zero?}
</pre></p>
<p>  What if you are going to include another condition? Of course, you can argue to simply hard code the new condition but that wouldn’t be fun <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   The solution by <a href="http://www.timmedina.net/">Tim</a> and Neil is to use procs which I’m sure would make <a href="http://www.rubyist.net/~matz/">Matz</a> very happy.</p>
<p>  <pre class="brush: ruby;">
    conditions = [
       proc { |i| i &gt; 5 },
       proc { |i| (i % 2).zero? },
       proc { |i| (i % 3).zero? }
     ]
    
    elements = (1..10).to_a
    
    matches = elements.select do |i|
      conditions.all? { |c| c[i] }
    end
    
    puts matches.join(',')
</pre> </p>
<p>  We can even add this filtering to the Array class, just in case we need to use this across our application.</p>
<p>  <pre class="brush: ruby;">
    class Array
      def matches(*conditions)
        select do |i|
          conditions.all? { |c| c[i] }
        end
      end
    end
    
    matches = elements.matches(*conditions)
    puts matches.join(',')
    
    matches = elements.matches( proc{ |i| i &gt; 5 })
    puts matches.join(',')
    
    matches = elements.matches( proc{ |i| i &gt; 5 }, proc{ |i| (i%3).zero? })
    puts matches.join(',')
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/459/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=459&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2010/04/26/ruby-101-how-to-filter-an-array-using-proc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby 101: How to add methods to a Ruby class</title>
		<link>http://gregmoreno.wordpress.com/2010/04/24/ruby-101-how-to-add-methods-to-a-ruby-class/</link>
		<comments>http://gregmoreno.wordpress.com/2010/04/24/ruby-101-how-to-add-methods-to-a-ruby-class/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 03:42:07 +0000</pubDate>
		<dc:creator>Greg Moreno</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gregmoreno.wordpress.com/?p=461</guid>
		<description><![CDATA[Let’s add a method that checks whether an Array has many elements. Let’s fix this by adding a new method to the class Array. Let’s implement Rails’ fancy ‘days.ago’ method: Now, add the days and ago methods to Fixnum.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=461&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>  Let’s add a method that checks whether an Array has many elements.</p>
<p>  <pre class="brush: ruby;">
  a = [1,2,3]
  a.many?  # NoMethodError: undefined method `many?'
</pre></p>
<p>  Let’s fix this by adding a new method to the class Array.</p>
<p>  <pre class="brush: ruby;">
  class Array
    def many?
      size &gt; 1
    end
  end
  
  a = [1,2,3]
  a.many?   # true
  
  b = [1]
  b.many? # false
  
  c = []
  b.many? # false
</pre></p>
<p>  Let’s implement Rails’ fancy  ‘days.ago’ method:</p>
<p>  <pre class="brush: ruby;">
  5.days.ago # NoMethodError: undefined method `days' for 3:Fixnum
</pre></p>
<p>  Now, add the days and ago methods to Fixnum.</p>
<p>  <pre class="brush: ruby;">
  class Fixnum
    def days
       self * 60 * 60 * 24   # we store seconds in a day
    end
  
    def ago
      Time.now - self
    end
  end
</pre> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregmoreno.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregmoreno.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregmoreno.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregmoreno.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregmoreno.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregmoreno.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregmoreno.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregmoreno.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregmoreno.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregmoreno.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregmoreno.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregmoreno.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregmoreno.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregmoreno.wordpress.com/461/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregmoreno.wordpress.com&amp;blog=5062655&amp;post=461&amp;subd=gregmoreno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gregmoreno.wordpress.com/2010/04/24/ruby-101-how-to-add-methods-to-a-ruby-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed357f6cb63c16d83b35fc29e5502e44?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
	</channel>
</rss>
