<?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/"
	>

<channel>
	<title>mynyml.rb</title>
	<atom:link href="http://mynyml.com/feed" rel="self" type="application/rss+xml" />
	<link>http://mynyml.com</link>
	<description>%w( yin yang minimalism ) #=&#62; Simplicity</description>
	<pubDate>Wed, 20 Jan 2010 20:10:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Continuous Testing, Productivity++</title>
		<link>http://mynyml.com/agile/continuous-testing-productivity</link>
		<comments>http://mynyml.com/agile/continuous-testing-productivity#comments</comments>
		<pubDate>Wed, 20 Jan 2010 20:10:30 +0000</pubDate>
		<dc:creator>mynyml</dc:creator>
		
		<category><![CDATA[agile]]></category>

		<category><![CDATA[agile development]]></category>

		<category><![CDATA[continuous testing]]></category>

		<guid isPermaLink="false">http://mynyml.com/?p=193</guid>
		<description><![CDATA[While preparing to present Watchr at CUSEC&#8217;s DemoCamp, I&#8217;ve come accross this research paper about continuous testing. From the research:
&#8220;Participants using continuous testing were three times as likely to complete the task before the deadline. Participants using continuous compilation were twice as likely to complete the task, providing empirical support to a common feature in [...]]]></description>
			<content:encoded><![CDATA[<p>While preparing to present <a href="http://github.com/mynyml/watchr">Watchr</a> at <a href="http://2010.cusec.net/">CUSEC</a>&#8217;s DemoCamp, I&#8217;ve come accross this <a href="http://groups.csail.mit.edu/pag/continuoustesting/">research paper</a> about continuous testing. From the research:</p>
<p><em><a href="http://www.cs.washington.edu/homes/mernst/pubs/ct-user-study-issta2004.pdf">&#8220;Participants using continuous testing <strong>were three times as likely to complete the task before the deadline</strong>. Participants using continuous compilation were twice as likely to complete the task, providing empirical support to a common feature in modern development environments. Most participants found continuous testing to be useful and believed that it helped them write better code faster, and 90% would recommend the tool to others. The participants did not find the tool distracting, and intuitively developed ways of incorporating the feedback into their workflow.&#8221;</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://mynyml.com/agile/continuous-testing-productivity/feed</wfw:commentRss>
		</item>
		<item>
		<title>Up-to-date Manifest with git post-commit hook</title>
		<link>http://mynyml.com/git/up-to-date-manifest-with-git-post-commit-hook</link>
		<comments>http://mynyml.com/git/up-to-date-manifest-with-git-post-commit-hook#comments</comments>
		<pubDate>Sat, 03 Oct 2009 15:07:39 +0000</pubDate>
		<dc:creator>mynyml</dc:creator>
		
		<category><![CDATA[git]]></category>

		<category><![CDATA[gem]]></category>

		<guid isPermaLink="false">http://mynyml.com/?p=185</guid>
		<description><![CDATA[I forgot to add project files to my gemspec once too many times. Never again.

$ cat .git/hooks/post-commit
#!/bin/sh
git ls-files > Manifest

]]></description>
			<content:encoded><![CDATA[<p>I forgot to add project files to my gemspec once too many times. Never again.</p>
<pre>
$ cat .git/hooks/post-commit
#!/bin/sh
git ls-files > Manifest
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mynyml.com/git/up-to-date-manifest-with-git-post-commit-hook/feed</wfw:commentRss>
		</item>
		<item>
		<title>Testing On Different Ruby Versions / Interpreters with rvm</title>
		<link>http://mynyml.com/ruby/testing-on-different-ruby-versions-interpreters-with-rvm</link>
		<comments>http://mynyml.com/ruby/testing-on-different-ruby-versions-interpreters-with-rvm#comments</comments>
		<pubDate>Sat, 19 Sep 2009 15:02:30 +0000</pubDate>
		<dc:creator>mynyml</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[jruby]]></category>

		<category><![CDATA[rubinius]]></category>

		<category><![CDATA[ruby 1.9]]></category>

		<category><![CDATA[rvm]]></category>

		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://mynyml.com/?p=160</guid>
		<description><![CDATA[I&#8217;ve been playing with a relatively new tool called rvm lately, and I&#8217;m loving it. rvm stands for Ruby Version Manager, and it does an exellent job at allowing different rubies to coexist. I currently have 7 versions installed on my machine:

ruby 1.8.6
ruby 1.8.7 patchlevel  72 (my system's default)
ruby 1.8.7 patchlevel 174
ruby 1.9.1
ruby 1.9.2 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with a relatively new tool called rvm lately, and I&#8217;m loving it. rvm stands for Ruby Version Manager, and it does an exellent job at allowing different rubies to coexist. I currently have 7 versions installed on my machine:</p>
<pre>
ruby 1.8.6
ruby 1.8.7 patchlevel  72 (my system's default)
ruby 1.8.7 patchlevel 174
ruby 1.9.1
ruby 1.9.2 preview1
jruby 1.3.1
rubinius 0.11.0
</pre>
<p>rvm makes it ridiculously easy to manage them.</p>
<h2>Installing</h2>
<p>Let&#8217;s start by installing rvm</p>
<pre>
$ gem install rvm
$ rvm-install
</pre>
<p>and follow the instructions rvm-install gives you. Next, let&#8217;s install ruby1.9 (v1.9.1 by default).</p>
<pre>
$ rvm install 1.9
</pre>
<p>That&#8217;s it! rvm <a href="http://github.com/wayneeseguin/rvm/blob/master/config/db">fetches</a> the source, compiles the interpreter, and installs it in its own sandbox in ~/.rvm</p>
<p>For moar awesomes, you can install some non-MRI/YARV interpreters.</p>
<pre>
$ rvm install jruby
$ rvm install rubinius
</pre>
<h2>Switching between versions</h2>
<pre>
$ rvm use 1.9
$ ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux]
$ which ruby
/home/mynyml/.rvm/ruby-1.9.1-p243/bin/ruby
$ rvm use system  #revert to using your system's ruby
$ ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
$ which ruby
/usr/bin/ruby
</pre>
<p>This speaks for itself, I believe.</p>
<h2>Gems</h2>
<p>Because each new version lives in its own sandbox, it starts off almost gemless (rvm pre-installs RubyGems and rake). You can install gems just as you normally would.</p>
<pre>
$ rvm use 1.9
$ gem install mynyml-every  #don't use sudo
$ rvm gemdir
/home/mynyml/.rvm/gems/ruby/1.9.1
$ gem list

*** LOCAL GEMS ***

mynyml-every (1.0)
rake (0.8.7)
</pre>
<h2>Cross Version Testing</h2>
<p>Here&#8217;s a rake task that will allow you to run your app&#8217;s tests across multiple ruby versions (provided you defined your own <tt>test</tt> task separately)</p>
<pre>
namespace(:test) do
  desc "Run tests on multiple ruby versions"
  task(:portability) do
    versions = %w( 1.8.6  1.8.7  1.9  jruby  rubinius )
    versions.each do |version|
      system <<-BASH
        bash -c 'source ~/.rvm/scripts/rvm;
                 rvm use #{version};
                 echo "-------- `ruby -v` ---------\n";
                 rake -s test'
      BASH
    end
  end
end
</pre>
<p>And run with:</p>
<pre>
$ rake -s test:portability
</pre>
<p>The reason the task looks hackish is because <tt>rvm</tt> isn&#8217;t a script, but a bash function. This function is loaded automatically when you open up a new shell because of the <tt>source</tt> line <tt>rvm-install</tt> added to your .bashrc file, but .bashrc itself isn&#8217;t loaded when you use <tt>#system</tt>.  So the rake task first sources that function, and then runs everything else within the same session so that it uses its environment.</p>
<p><strong>[update]</strong> As Wayne pointed out in the comments, there is a new rvm idiom that can be used to achieve this:</p>
<pre>
rvm 1.8.6,1.8.7,1.9,jruby,rubinius rake -s test
</pre>
<p>The <a href="http://rvm.beginrescueend.com">rvm docs</a> have also been updated to include this info.</p>
<h2>Links</h2>
<p>rvm&#8217;s <a href="http://rvm.beginrescueend.com">official website</a> has pretty good docs. You can also get a fairly good summary of functionality with</p>
<pre>
$ rvm help
</pre>
<p>source:    <a href="http://github.com/wayneeseguin/rvm/">http://github.com/wayneeseguin/rvm/</a><br />
site/docs: <a href="http://rvm.beginrescueend.com/">http://rvm.beginrescueend.com/</a><br />
tracker:   <a href="https://www.pivotaltracker.com/projects/26822">https://www.pivotaltracker.com/projects/26822</a><br />
group:     <a href="http://groups.google.com/group/rubyversionmanager/">http://groups.google.com/group/rubyversionmanager/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mynyml.com/ruby/testing-on-different-ruby-versions-interpreters-with-rvm/feed</wfw:commentRss>
		</item>
		<item>
		<title>Flexible Continuous Testing</title>
		<link>http://mynyml.com/ruby/flexible-continuous-testing</link>
		<comments>http://mynyml.com/ruby/flexible-continuous-testing#comments</comments>
		<pubDate>Tue, 15 Sep 2009 05:14:01 +0000</pubDate>
		<dc:creator>mynyml</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[continuous testing]]></category>

		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://mynyml.com/?p=122</guid>
		<description><![CDATA[
Autotest ]]></description>
			<content:encoded><![CDATA[<br />
<h2>Autotest <3</h2>
<p>Like lots of rubyists, I love agile development, BDD/TDD and continuous<br />
testing. And one of my favourite pieces of software for that task is Autotest. Whenever I start a new project, the first thing I do is open up a test file, write a placeholder test case, and fire up autotest. It&#8217;s the one gem I use on every single application I write; from gems to rails apps to bare bones rack apps, it&#8217;s always there to make my development much more enjoyable.</p>
<p>Well, almost always.</p>
<p>Some time ago I was <a href="http://github.com/mynyml/phocus/blob/497dbf44fd3f6955ba77165ce4d121d78fdbcedf/test/test_phocus.rb"> working on a gem</a> where I wanted to use the Expectations test framework.  Expectations is not based on test/unit (as opposed to <a href="http://github.com/jeremymcanally/context"> context</a> or <a href="http://github.com/citrusbyte/contest/">contest</a>, for instance). But Autotest, by default, requires test/unit. The result wasn&#8217;t great.</p>
<p>Not too long ago, I was getting excited about <a href="http://github.com/defunkt/rip/">rip</a>, an alternative ruby package manager. So I tried using it. But autotest automatically requires rubygems.  Not so compatible.</p>
<p>Not too long ago I started working on a webapp that has regular MRI based tests alongside JRuby based tests. But Autotest automatically ran the test suite with /usr/bin/ruby1.8. That just plain won&#8217;t work.</p>
<h2>Watchr</h2>
<p>&#8220;Hi. I&#8217;m Martin &#8230;. and I&#8217;m a continuous testing addict&#8221;</p>
<p>I was beginning to feel the withdrawal symptoms. So I started working on a solution that would satisfy my cravings in any dev environment. The result is <a href="http://github.com/mynyml/watchr">Watchr</a>, a continuous testing tool similar to autotest, but with a different philosophy.</p>
<p>Watchr aims to be much more flexible, at the cost of a few lines of setup. That is, it will read a small script file and run tests accordingly. The script file uses a very simple ruby DSL. Very simple as in a single method, that&#8217;s all it needs.</p>
<pre>
#           pattern                   action
watch('test/test_.*\.rb') {|md| system "ruby #{md[0]}"}
</pre>
<p>This tells watchr to monitor all test files (in this case all ruby files in the test/ directory that start with &#8220;test_&#8221;), and when one of those is saved, runs it with <tt>ruby</tt>. A continuous testing script for a basic project could be</p>
<pre>
watch('test/test_.*\.rb') {|md| system "ruby #{md[0]}"}
watch('lib/(.*)\.rb')     {|md| system "ruby test/test_#{md[1]}.rb"}
</pre>
<p>which, in addition to running any saved test file as above, will also run a lib file&#8217;s associated test. This mimics the equivalent autotest behaviour.</p>
<p>The command follows the structure:</p>
<pre>
watch('pattern') {|match_data_object| command_to_run }
</pre>
<p>Leaving the action user defined is the key. You can run JRuby-based tests, use rip, write your test suite with alternative testing frameworks, &#8230; or any combination of these.</p>
<p>For a good example of actual scripts, be sure to check out watchr&#8217;s own <a href="http://github.com/mynyml/watchr/blob/master/specs.watchr">specs.watchr</a> and <a href="http://github.com/mynyml/watchr/blob/master/docs.watchr">docs.watchr</a> scripts.</p>
<p>Install:</p>
<pre>
gem install watchr --source=http://gemcutter.org
</pre>
<p>Run:</p>
<pre>
$ cd to/your/project/root
$ watchr path/to/script
</pre>
<h2>Links</h2>
<p>source: <a href="http://github.com/mynyml/watchr">http://github.com/mynyml/watchr</a><br />
wiki:   <a href="http://wiki.github.com/mynyml/watchr">http://wiki.github.com/mynyml/watchr</a><br />
bug tracker:   <a href="http://github.com/mynyml/watchr/issues">http://github.com/mynyml/watchr/issues</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mynyml.com/ruby/flexible-continuous-testing/feed</wfw:commentRss>
		</item>
		<item>
		<title>Focused tests with Phocus</title>
		<link>http://mynyml.com/ruby/focused-tests-with-phocus</link>
		<comments>http://mynyml.com/ruby/focused-tests-with-phocus#comments</comments>
		<pubDate>Thu, 11 Jun 2009 13:25:02 +0000</pubDate>
		<dc:creator>mynyml</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[focus]]></category>

		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://mynyml.com/?p=87</guid>
		<description><![CDATA[If you ever comment out big chunks of your test suite so you can concentrate
on a single test, or use your editor&#8217;s ability to run the test under your
cursor, you&#8217;ve been focusing tests.
I make extensive use of this functionality myself, and though there are
already a few ways to do it (editor, autotest, &#8230;), none of [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever comment out big chunks of your test suite so you can concentrate<br />
on a single test, or use your editor&#8217;s ability to run the test under your<br />
cursor, you&#8217;ve been focusing tests.</p>
<p>I make extensive use of this functionality myself, and though there are<br />
already a few ways to do it (editor, autotest, &#8230;), none of them worked well<br />
enough for true focusing (the editor is thrown off by contexts, etc).</p>
<p>So I finally put together a gem to do focus the way I needed it to work. To<br />
use, simply call the <tt>focus</tt> method above the test you want focused.</p>
<pre>
gem install phocus --source http://gemcutter.org
</pre>
<pre>
require 'test/unit'
require 'phocus'

class TestWidget < Test::Unit::TestCase

  def test_foo
    assert false
  end

  focus
  def test_bar
    assert true
  end

  def test_baz
    assert false
  end
end
</pre>
<p>Running this suite will only call <tt>test_bar</tt> (and the suite will pass).</p>
<p><tt>focus</tt> can be used on multiple tests, including across test suites.</p>
<pre>
class TestWidget < Test::Unit::TestCase

  focus
  def test_foo
  end

  def test_bar
  end
end

class TestGatget < Test::Unit::TestCase

  def test_abc
  end

  focus
  def test_def
  end
end
</pre>
<p>Running these will only call <tt>test_foo</tt> and <tt>test_def</tt>.</p>
<p>And Phocus isn&#8217;t affraid of fancy tests, either:</p>
<pre>
class TestUser < Test::Unit::TestCase

  context "Authentication" do
    test "should deny on wrong username" do
      ...
    end

    focus
    test "should deny on wrong password" do
      ...
    end
  end
end
</pre>
<p>will work just as well. In fact, Phocus is known to work with at least the<br />
following testing frameworks:</p>
<ul>
<li>test/unit</li>
<li><a href="http://github.com/seattlerb/minitest">minitest/unit</a></li>
<li><a href="http://github.com/thoughtbot/shoulda">shoulda</a></li>
<li><a href="http://github.com/jeremymcanally/context">context</a></li>
<li><a href="http://github.com/citrusbyte/contest">contest</a></li>
</ul>
<h3>Links</h3>
<p>Source: <a href="http://github.com/mynyml/phocus">http://github.com/mynyml/phocus</a><br />
Issues: <a href="http://github.com/mynyml/phocus/issues">http://github.com/mynyml/phocus/issues</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mynyml.com/ruby/focused-tests-with-phocus/feed</wfw:commentRss>
		</item>
		<item>
		<title>stdout output tests</title>
		<link>http://mynyml.com/ruby/stdout-output-tests</link>
		<comments>http://mynyml.com/ruby/stdout-output-tests#comments</comments>
		<pubDate>Thu, 02 Apr 2009 05:02:14 +0000</pubDate>
		<dc:creator>mynyml</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[output]]></category>

		<category><![CDATA[stdout]]></category>

		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://mynyml.com/?p=66</guid>
		<description><![CDATA[I was working on simple_example a few days ago and needed to test the output&#8217;s formatting.
The first step is to capture the output so that we can compare it later. A simple way to do this is to swap $stdout for a StringIO object. ($stdout is an IO object. Kernel#puts and Kernel#print are wrappers around [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on <a href="http://github.com/mynyml/simple_example">simple_example</a> a few days ago and needed to test the output&#8217;s formatting.</p>
<p>The first step is to capture the output so that we can compare it later. A simple way to do this is to swap $stdout for a StringIO object. ($stdout is an IO object. Kernel#puts and Kernel#print are wrappers around $stdout.puts and $stdout.write)</p>
<pre>
def keep_stdout(&#038;block)
  begin
    orig_stream, $stdout = $stdout, StringIO.new
    block.call($stdout)
  ensure
    s, $stdout = $stdout.string, orig_stream
    s
  end
end
</pre>
<p>Clearly we want to restore the stdout stream after we are done with our call so that we can get out test restults printed.</p>
<p>Next, let&#8217;s create an assertion that wraps our stdout capture method.</p>
<pre>
def assert_output(expected, &#038;block)
  keep_stdout do |stdout|
    block.call
    if expected.is_a?(Regexp)
      assert_match expected, stdout.string
    else
      stdout.string.should be(expected.to_s)
      assert_equal expected.to_s, stdout.string
    end
  end
end
</pre>
<p>The regexp matching is so we can assert that the output <em>contains</em> what we&#8217;re looking for, as opposed to being exactly equal to it.</p>
<p>Now we can do:</p>
<pre>
assert_output('abc') { puts "abc" }      #=> true
assert_output(/abc/) { puts "abc\ndef" } #=> true
</pre>
<p>If you have slightly more complex strings that you want to partially match, remember that you have to escape them first as they might contain special regexp chars. This can be achieved with a small string extention:</p>
<pre>
class String
  def to_regexp
    Regexp.new(Regexp.escape(self))
  end
end
</pre>
<p>#to_regexp is probably a bad name, but it&#8217;s only a test helper so it&#8217;ll work for now.</p>
<p>This allows:</p>
<pre>
assert_output("(1 + 1)".to_regexp) do
  puts "(2 + 2)\n(1 + 1)\nabc"
end
#=> true
</pre>
<p>To test for string formatting, though, I needed the expected string to be more complex than &#8216;abc&#8217;.</p>
<pre>
def test_formatting
  out = <<-STR.unindent
        (1 + 1)
    #=> 2
        (2 + 2)
    #=> 4
  STR
  # ...
end
</pre>
<p>This uses the small <a href="http://github.com/mynyml/unindent">unindent</a> gem to allow us to keep normal indentation; otherwise we&#8217;d have to write:</p>
<pre>
def test_formatting
  out = <<-STR
    (1 + 1)
#=> 2
    (2 + 2)
#=> 4
  STR
  # ...
end
</pre>
<p>Which works fine, of course. Just not as fun.</p>
<h3>Putting it all together</h3>
<pre>
require 'test/unit'
require 'rubygems'
require 'unindent'

class OutputTest < Test::Unit::TestCase
  def test_formatting
    out = <<-STR.unindent
          (1 + 1)
      #=> 2
          (2 + 2)
      #=> 4
      ----------
          (3 + 3)
      #=> 6
      ----------
    STR
    assert_output(out) do
      @obj.first_method
      @obj.other_method
    end
  end
end
</pre>
<p>You can see real life usage in <a href="http://github.com/mynyml/simple_example">simple_example</a>&#8217;s <a href="http://github.com/mynyml/simple_example/blob/a2d2f3e15684d7ca5ae447485dfd7ee4b6d4ce3b/test/test_simple_example.rb">test</a> file.</p>
]]></content:encoded>
			<wfw:commentRss>http://mynyml.com/ruby/stdout-output-tests/feed</wfw:commentRss>
		</item>
		<item>
		<title>Enumerable#every</title>
		<link>http://mynyml.com/ruby/enumerable_every</link>
		<comments>http://mynyml.com/ruby/enumerable_every#comments</comments>
		<pubDate>Thu, 26 Mar 2009 06:59:59 +0000</pubDate>
		<dc:creator>mynyml</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[enumerable]]></category>

		<category><![CDATA[every]]></category>

		<category><![CDATA[map]]></category>

		<category><![CDATA[Symbol#to_proc]]></category>

		<guid isPermaLink="false">http://mynyml.com/?p=15</guid>
		<description><![CDATA[
By now rubists know the Symbol#to_proc idiom pretty well

  [1.4, 2.4, 3.4].map {&#124;n&#124; n.floor } #=> [1, 2, 3]
  [1.4, 2.4, 3.4].map(&#038;:floor)       #=> [1, 2, 3]

It has become so popular, in fact, that it&#8217;s been included in ruby 1.8.7
Funny thing is, the block form is only an [...]]]></description>
			<content:encoded><![CDATA[<p>
By now rubists know the Symbol#to_proc idiom pretty well</p>
<pre>
  [1.4, 2.4, 3.4].map {|n| n.floor } #=> [1, 2, 3]
  [1.4, 2.4, 3.4].map(&#038;:floor)       #=> [1, 2, 3]
</pre>
<p>It has become so popular, in fact, that it&#8217;s been included in <a href='http://svn.ruby-lang.org/repos/ruby/tags/v1_8_7/NEWS'>ruby 1.8.7</a></p>
<p>Funny thing is, the block form is only an extra 3 characters (6 if you want to count spaces). Though I guess the additional &#8220;effort&#8221; needed to stop and think about what to name the variable is somewhat distracting, especially since the variable is redundant anyway. Regardless, it&#8217;s enough of an improvement on such a commonly used idiom that we happily adopted it.</p>
<p>But after having used it plenty (some rails ./script/console hacking sessions can make quite intense use of it), its syntax started feeling heavy.</p>
<p>My favorite way to access an object&#8217;s internals is by far the good ol&#8217; dot. I sometimes use OpenStruct instead of a hash just so I can access the values as methods, and I use `<a href='http://github.com/raganwald/andand' title='andand'>andand</a>.method` instead of `<a href='http://ryandaigle.com/articles/2008/11/20/what-s-new-in-edge-rails-object-try'>try</a>(:method)` for the same reason.</p>
<p>I knew I would be happier if I could use the same trick with #map, so I wrote an Enumerable method. Compare,</p>
<pre>
  enum = [1.4, 2.4 ,3.4]
  enum.map {|n| n.floor } #=> [1, 2, 3]
  enum.map(&#038;:floor)       #=> [1, 2, 3]
  enum.every.floor        #=> [1, 2, 3]
</pre>
<p>It has the added advantage that it can take arguments and blocks, so it&#8217;s not restricted to only a few methods.</p>
<pre>
  %w( axb dxf ).every.gsub(/x/,'y')
  %w( axb dxf ).every.gsub(/x/) { 'y' }
</pre>
<p>I turned it into a gem so I could easily use it in irb and the rails console, or add it to my rails projects.</p>
<p>To use it:</p>
<pre>
  # on the command line
  gem sources --add http://gems.github.com
  gem install mynyml-every

  # in your app
  require 'rubygems'
  require 'every'
</pre>
<p>If you want to use #every as part of a gem or plugin but don&#8217;t want to add a dependency for only a few uses, you can simply make it a git submodule, or even just copy the content into your app since it&#8217;s contained in a single file.</p>
<p>Project page: <a href='http://github.com/mynyml/every' title='every'>http://github.com/mynyml/every</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mynyml.com/ruby/enumerable_every/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
