Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Took out Windows line endings.

  • Loading branch information...
commit 53c24c2f5c06af9de89ae9f9e71d4f4414ca7b7b 1 parent b467af9
@gilesbowkett gilesbowkett authored
Showing with 304 additions and 304 deletions.
  1. +304 −304 html/usage.html
View
608 html/usage.html 100755 → 100644
@@ -1,304 +1,304 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
- <meta name="description" content="Baddest Ruby gem evar." />
- <meta name="keywords" content="ruby, giles bowkett, batman, utility belt, gem, attack of the killer tomatoes" />
- <meta name="author" content="Giles Bowkett / Original design: Andreas Viklund - http://andreasviklund.com/" />
- <link rel="stylesheet" type="text/css" href="andreas00.css" media="screen,projection" />
- <title>Utility Belt: Usage</title>
-</head>
-
-<body>
- <div id="wrap">
- <div id="header">
- <h1><a href="http://utilitybelt.rubyforge.org">Utility Belt</a></h1>
- <p><strong>IRB tools, tricks, and techniques</strong></p>
- </div>
-
- <div id="avmenu">
- <h2 class="hide">Site menu:</h2>
- <ul>
- <li><a href="index.html">Overview</a></li>
- <li><a href="usage.html">Usage</a></li>
- <li><a href="authorship.html">Authorship</a></li>
- <li><a href="http://rubyforge.org/projects/utilitybelt/">RubyForge Project</a></li>
- </ul>
-
- </div>
-
- <div id="contentwide">
- <h2>Synopsis And Usage</h2>
-
-
- <h3>SYNOPSIS</h3>
-
- <p>Utility Belt gives you a ton of new options and techniques in IRB. (You may find yourself putting its language patches in actual projects as well.) The way to use Utility Belt is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file.</p>
-
- <p>Windows users have a couple options. The easiest is to define an environment variable called IRBRC and set it to the full path of your irbrc (e.g. "C:\Documents and Settings\<username>\_irbrc"). Presto, .irbrc for Windows. You could also set your HOME-Variable to any directory you want and put your ".irbrc" in there. (It needs to be called ".irbrc", "_irbrc" won't work). Since Windows Explorer won't let you create a file with a dot in the beginning, use any text editor (Notepad will do just fine) and "Save As" to save it as ".irbrc". (The quotation marks make the magic happen.) We don't recommend this if you're also using MSYS or Cygwin, as they use the same variable for their own purposes.</p>
-
- <p>Adding Utility Belt to your .irbrc is easy:</p>
-
-<pre>require 'rubygems'
-require 'utility_belt'</pre>
-
- <p>To use the Amazon shortcuts, you also need to set some environment variables. See the section on S3 under "Usage" for more. Also, if your terminal has a light background, you'll need to enable the light-background syntax coloring theme - see the section on themes under "Usage" for more.</p>
-
- <h3>USAGE</h3>
-
- <p>Using each of Utility Belt's tools is different:</p>
-
- <h4>Interactively edit IRB code in your preferred text editor</h4>
-
- <p>If your preferred text editor is vi(m), emacs, or TextMate, there are built-in commands: vi, emacs, and mate, respectively. To use another editor, use this command:</p>
-
-<pre>edit_interactively(:the_name_of_my_editor)</pre>
-
- <p>or</p>
-
-<pre>edit_interactively("the name of my editor")</pre>
-
- <p>or</p>
-
-<pre>edit_interactively("/the/path/to/my/editor")</pre>
-
- <p>If you're wondering why the method name is so ridiculously long, <a href="http://gilesbowkett.blogspot.com/2007/12/utility-belt-vs-rails.html" title="Giles Bowkett: Utility Belt vs. Rails">there's a story there</a>.</p>
-
- <h4>Read from and write to OS X or Windows clipboard</h4>
-
- <p>To read:</p>
-
-<pre>Clipboard.read</pre>
-
- <p>To write:</p>
-
-<pre>Clipboard.write("something")</pre>
-
- <h4>Post your code to Pastie with one command (OS X and Windows only)</h4>
-
- <p>You must first equip the UtilityBelt with pastie in your .irbrc:</p>
-
-<pre>UtilityBelt.equip(:pastie)</pre>
-
- <p>This line will also automatically equip the Clipboard, which is required to use pastie.</p>
-
- <p>First copy some code into your clipboard, or put it there with the Clipboard.write() class method. Then use the command:</p>
-
-<pre>pastie</pre>
-
- <p>or the shortcut version:</p>
-
-<pre>pst</pre>
-
- <p>Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X and Windows only because it uses the Clipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)</p>
-
- <h4>Unix-style history buffer</h4>
-
- <p>Use "h" or "history" to view your command history, and "h! 123" to re-invoke command #123 in your buffer. "h!" with no args will run the last command.</p>
-
- <h4>Write command history to file or vi</h4>
-
- <p>To write your history to a file, use "history_write('/path/to/file')". To edit your history in vi, use "history_to_vi" or its shortcut alias "hvi".</p>
-
- <h4>Grep classes and methods for strings</h4>
-
- <p>Classes:</p>
-
-<pre>&gt;&gt; grep_classes(&quot;ixnum&quot;)
-#=&gt; [&quot;Fixnum&quot;]
-
-&gt;&gt; grep_classes(&quot;num&quot;)
-#=&gt; [&quot;Bignum&quot;, &quot;Fixnum&quot;, &quot;Numeric&quot;, &quot;REXML::SyncEnumerator&quot;]</pre>
-
- <p>Methods:</p>
-
-<pre>&gt;&gt; &quot;any arbitrary string&quot;.grep_methods(&quot;pretty&quot;)
-#=&gt; [&quot;pretty_inspect&quot;, &quot;pretty_print_instance_variables&quot;,
-&quot;pretty_print_inspect&quot;, &quot;pretty_print&quot;, &quot;pretty_print_cycle&quot;]
-
-&gt;&gt; 32.grep_methods(&quot;*&quot;)
-#=&gt; [&quot;*&quot;, &quot;**&quot;]</pre>
-
- <p>At some point it'll probably be a good idea to add regex support for these methods. (Of course if I do that, I'll probably have to change the name from grep to ack.)</p>
-
- <h4>Verbosity controls for regular IRB and Rails console</h4>
-
- <p>regular IRB: "verbose" or "v" / "quiet" or "q"</p>
-
- <p>Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.)</p>
-
- <h4>Finder shortcuts for Rails console</h4>
-
-<pre>user(:all) / user(1)</pre>
-
- <p>instead of</p>
-
-<pre>User.find(:all) / User.find(1)</pre>
-
- <p>Supports arbitrarily complex finds.</p>
-
- <h4>Upload shortcut for Amazon S3</h4>
-
- <p>First, define your secret keys in your environment variables:</p>
-
-<pre>export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo'
-export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar'</pre>
-
- <p>(Obviously, replace those with actual values.)</p>
-
- <p>Then, you can use</p>
-
-<pre>aws_upload("bucket_name","filename")</pre>
-
- <p>To easily upload public-access files. This method will automatically connect to Amazon S3 for you, if your keys are defined in your environment variables. It also writes the resulting Amazon URL to your clipboard, if you're on OS X, so you can easily share the file with others. Note that you have to create the initial buckets manually - see <a href="http://amazon.rubyforge.org" title="AWS::S3 - Ruby Library for Amazon Simple Storage Service (S3)">amazon.rubyforge.org</a> for details on that.</p>
-
- <p>A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file:</p>
-
-<pre>def my_bucket_name(filename)
- aws_upload("my_default_bucket",filename)
-end</pre>
-
- <h4>Command-line Amazon S3 upload script</h4>
-
-<p>Utility Belt also includes <code>amazon</code>, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is:</p>
-
-<pre>amazon -b my_bucket_name filename other_filename</pre>
-
-<p>(For any arbitrary number of filenames.)</p>
-
-<p>Anytime you want to upload a file to your default bucket on S3, for example, the "images" bucket for your blog - or the "mp3" bucket if you're running a blog like Projectionist - all you have to do is</p>
-
-<pre>amazon -b blog_files some_file.name</pre>
-
-<p>Or</p>
-
-<pre>amazon --bucket blog_files some_file.name</pre>
-
-<p>And you're good to go. Of course, if that were too many characters to type, you could always take it one step further with a shell script. For instance, in bash:</p>
-
-<pre>alias b1="amazon --bucket my_main_bucket $1"
-alias b2="amazon --bucket my_other_bucket $1"</pre>
-
-<p>And then you would only have to type:</p>
-
-<pre>b1 file.name</pre>
-
-<p>And of course tab completion will handle all the typing of the file name, assuming you choose your file names deliberately ahead of time to make tab completion effective, in which case all you have to type is "b1 f[tab]" and bam.</p>
-
- <h4>Command-line Google shortcut (OS X only)</h4>
-
-<p>To pop open a new window in your default browser with Google search results for a given search term, do:</p>
-
-<pre>google "any given term"</pre>
-
-<p>For one-word terms, you can omit the quotes:</p>
-
-<pre>google term</pre>
-
-<p>If you already have the search term in your clipboard, you can just type:</p>
-
-<pre>google</pre>
-
-<p>(The last approach is useful for unusual command-line error messages.)</p>
-
- <h4>Auto-indentation</h4>
-
- <p>Just type as normally. This just enables built-in but underused functionality in IRB. (The IRB default auto-indentation isn't perfect, but it clobbers the living hell out of no indentation at all.)</p>
-
- <h4>_ special variable (like Unix shell var !!)</h4>
-
- <p>More activation of built-in but underused functionality in IRB. _ functions like !! in Unix, with one subtle difference. Instead of re-issuing the previous command in your history, it gives you the last result of evaluating a command. This means when you start a new IRB session, _ won't go to your history, it'll just give you nil, and it means that some commands can't be repeated exactly. Nine out of ten times, however, it's pretty much the same thing.</p>
-
- <p>Note that when combined with the h! in the command history code, you basically have two synonyms for !! here. Neither one is an exact replica, but between the two of them, you should have what you need.</p>
-
- <h4>Extremely basic themes for Wirble syntax coloring</h4>
-
- <p>Utility Belt incorporates <a href="http://pablotron.org/software/wirble/" title="Pablotron: Wirble">Wirble</a> as a dependency. Wirble provides syntax coloring. Utility Belt allows you to choose between two syntax coloring themes: Wirble's default, and an alternate color set for terminals with light backgrounds. The default theme is enabled by default (duh), but if you have a terminal with a light background, you can enable the light-background theme just by putting the following line of code in your .irbrc:</p>
-
-<pre>UtilityBelt::Themes.background(:light)</pre>
-
- <p>To revert back to the default, just use this:</p>
-
-<pre>UtilityBelt::Themes.background(:dark)</pre>
-
-<p>To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble.</p>
-
- <h4>Pascal/JavaScript-style "with" statement</h4>
-
- <p>I use this with RSpec's spec_helper. Instead of:</p>
-
-<pre>Spec::Runner.configure do |config|
- config.use_transactional_fixtures = true
- config.use_instantiated_fixtures = false
- config.fixture_path = RAILS_ROOT + '/spec/fixtures'
- config.mock_with :flexmock
-end</pre>
-
- <p>I do this:</p>
-
-<pre>Spec::Runner.configure do |config|
- with(config) do
- use_transactional_fixtures = true
- use_instantiated_fixtures = false
- fixture_path = RAILS_ROOT + '/spec/fixtures'
- mock_with :flexmock
- end
-end</pre>
-
- <p>Note however that this blew up once and I have no idea why. Caveat emptor, et cetera.</p>
-
- <h4>String#to_proc</h4>
-
- <p>Syntactic sugar for functional programming. (<a href="http://weblog.raganwald.com/2007/10/stringtoproc.html" title="String#to_proc">More detail here</a>.) Rails' Symbol#to_proc is also included.</p>
-
-<pre>(1..3).map(&amp;&apos;*2&apos;) =&gt; [2, 4, 6]
-(1..3).map(&amp;&apos;[-1, _, 0]&apos;) =&gt; [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]]
-(1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;[2]&apos;) =&gt; [2, 4, 6]
-(1..5).select(&amp;&apos;&gt;2&apos;) =&gt; [3, 4, 5]
-(1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;.call(2)&apos;) =&gt; [2, 4, 6]
-[5].map(&amp;&quot;(1.._).inject(&amp;&apos;*&apos;)&quot;) =&gt; [120]</pre>
-
- <h4>Add and subtract Hashes with + and -</h4>
-
-<pre>{:a =&gt; :b} + {:c =&gt; :d} = {:a =&gt; :b, :c =&gt; :d}
-{:a =&gt; :b, :c =&gt; :d} - {:c =&gt; :d} = {:a =&gt; :b}
-{:a =&gt; :b, :c =&gt; :d} - :c = {:a =&gt; :b}</pre>
-
- <p>You could already do this with Arrays; now you can do it with Hashes as well. (I was kinda surprised the first time I tried to do this and realized I'd have to write it myself.)</p>
-
-
- <h4>Grammatically-correct is_an? method - no more "is_a? Array" statements</h4>
-
-<pre>&gt;&gt; [].is_an? Array
-#=&gt; true</pre>
-
- <p>Most people don't care, but personally, "is_a? Array" drives me completely insane.</p>
-
- <h4>Object#not</h4>
-
- <p>Replace this:</p>
-
-<pre>if !response.incomplete? &amp;&amp; !response.invalid? &amp;&amp; response.total &gt; 0</pre>
-
- <p>With this:</p>
-
-<pre>if response.not.incomplete? &amp;&amp; response.not.invalid? &amp;&amp; response.total &gt; 0</pre>
-
- <p>Syntactic sugar for boolean conditions. (<a href="http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html" title="Jay Fields Thoughts: Ruby: Adding a "not" method for readability">More detail here</a>.)</p>
-
- <h4>One-character exit command</h4>
-
-<pre>x</pre>
-
- <p>Because life is too short to type whole words.</p>
-
-
- </div>
-
- <div id="footer">
- <p>Copyright &copy; 2007 Giles Bowkett | Design by <a href="http://andreasviklund.com">Andreas Viklund</a>.</p>
- </div>
- </div>
-</body>
-</html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
+ <meta name="description" content="Baddest Ruby gem evar." />
+ <meta name="keywords" content="ruby, giles bowkett, batman, utility belt, gem, attack of the killer tomatoes" />
+ <meta name="author" content="Giles Bowkett / Original design: Andreas Viklund - http://andreasviklund.com/" />
+ <link rel="stylesheet" type="text/css" href="andreas00.css" media="screen,projection" />
+ <title>Utility Belt: Usage</title>
+</head>
+
+<body>
+ <div id="wrap">
+ <div id="header">
+ <h1><a href="http://utilitybelt.rubyforge.org">Utility Belt</a></h1>
+ <p><strong>IRB tools, tricks, and techniques</strong></p>
+ </div>
+
+ <div id="avmenu">
+ <h2 class="hide">Site menu:</h2>
+ <ul>
+ <li><a href="index.html">Overview</a></li>
+ <li><a href="usage.html">Usage</a></li>
+ <li><a href="authorship.html">Authorship</a></li>
+ <li><a href="http://rubyforge.org/projects/utilitybelt/">RubyForge Project</a></li>
+ </ul>
+
+ </div>
+
+ <div id="contentwide">
+ <h2>Synopsis And Usage</h2>
+
+
+ <h3>SYNOPSIS</h3>
+
+ <p>Utility Belt gives you a ton of new options and techniques in IRB. (You may find yourself putting its language patches in actual projects as well.) The way to use Utility Belt is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file.</p>
+
+ <p>Windows users have a couple options. The easiest is to define an environment variable called IRBRC and set it to the full path of your irbrc (e.g. "C:\Documents and Settings\<username>\_irbrc"). Presto, .irbrc for Windows. You could also set your HOME-Variable to any directory you want and put your ".irbrc" in there. (It needs to be called ".irbrc", "_irbrc" won't work). Since Windows Explorer won't let you create a file with a dot in the beginning, use any text editor (Notepad will do just fine) and "Save As" to save it as ".irbrc". (The quotation marks make the magic happen.) We don't recommend this if you're also using MSYS or Cygwin, as they use the same variable for their own purposes.</p>
+
+ <p>Adding Utility Belt to your .irbrc is easy:</p>
+
+<pre>require 'rubygems'
+require 'utility_belt'</pre>
+
+ <p>To use the Amazon shortcuts, you also need to set some environment variables. See the section on S3 under "Usage" for more. Also, if your terminal has a light background, you'll need to enable the light-background syntax coloring theme - see the section on themes under "Usage" for more.</p>
+
+ <h3>USAGE</h3>
+
+ <p>Using each of Utility Belt's tools is different:</p>
+
+ <h4>Interactively edit IRB code in your preferred text editor</h4>
+
+ <p>If your preferred text editor is vi(m), emacs, or TextMate, there are built-in commands: vi, emacs, and mate, respectively. To use another editor, use this command:</p>
+
+<pre>edit_interactively(:the_name_of_my_editor)</pre>
+
+ <p>or</p>
+
+<pre>edit_interactively("the name of my editor")</pre>
+
+ <p>or</p>
+
+<pre>edit_interactively("/the/path/to/my/editor")</pre>
+
+ <p>If you're wondering why the method name is so ridiculously long, <a href="http://gilesbowkett.blogspot.com/2007/12/utility-belt-vs-rails.html" title="Giles Bowkett: Utility Belt vs. Rails">there's a story there</a>.</p>
+
+ <h4>Read from and write to OS X or Windows clipboard</h4>
+
+ <p>To read:</p>
+
+<pre>Clipboard.read</pre>
+
+ <p>To write:</p>
+
+<pre>Clipboard.write("something")</pre>
+
+ <h4>Post your code to Pastie with one command (OS X and Windows only)</h4>
+
+ <p>You must first equip the UtilityBelt with pastie in your .irbrc:</p>
+
+<pre>UtilityBelt.equip(:pastie)</pre>
+
+ <p>This line will also automatically equip the Clipboard, which is required to use pastie.</p>
+
+ <p>First copy some code into your clipboard, or put it there with the Clipboard.write() class method. Then use the command:</p>
+
+<pre>pastie</pre>
+
+ <p>or the shortcut version:</p>
+
+<pre>pst</pre>
+
+ <p>Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X and Windows only because it uses the Clipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)</p>
+
+ <h4>Unix-style history buffer</h4>
+
+ <p>Use "h" or "history" to view your command history, and "h! 123" to re-invoke command #123 in your buffer. "h!" with no args will run the last command.</p>
+
+ <h4>Write command history to file or vi</h4>
+
+ <p>To write your history to a file, use "history_write('/path/to/file')". To edit your history in vi, use "history_to_vi" or its shortcut alias "hvi".</p>
+
+ <h4>Grep classes and methods for strings</h4>
+
+ <p>Classes:</p>
+
+<pre>&gt;&gt; grep_classes(&quot;ixnum&quot;)
+#=&gt; [&quot;Fixnum&quot;]
+
+&gt;&gt; grep_classes(&quot;num&quot;)
+#=&gt; [&quot;Bignum&quot;, &quot;Fixnum&quot;, &quot;Numeric&quot;, &quot;REXML::SyncEnumerator&quot;]</pre>
+
+ <p>Methods:</p>
+
+<pre>&gt;&gt; &quot;any arbitrary string&quot;.grep_methods(&quot;pretty&quot;)
+#=&gt; [&quot;pretty_inspect&quot;, &quot;pretty_print_instance_variables&quot;,
+&quot;pretty_print_inspect&quot;, &quot;pretty_print&quot;, &quot;pretty_print_cycle&quot;]
+
+&gt;&gt; 32.grep_methods(&quot;*&quot;)
+#=&gt; [&quot;*&quot;, &quot;**&quot;]</pre>
+
+ <p>At some point it'll probably be a good idea to add regex support for these methods. (Of course if I do that, I'll probably have to change the name from grep to ack.)</p>
+
+ <h4>Verbosity controls for regular IRB and Rails console</h4>
+
+ <p>regular IRB: "verbose" or "v" / "quiet" or "q"</p>
+
+ <p>Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.)</p>
+
+ <h4>Finder shortcuts for Rails console</h4>
+
+<pre>user(:all) / user(1)</pre>
+
+ <p>instead of</p>
+
+<pre>User.find(:all) / User.find(1)</pre>
+
+ <p>Supports arbitrarily complex finds.</p>
+
+ <h4>Upload shortcut for Amazon S3</h4>
+
+ <p>First, define your secret keys in your environment variables:</p>
+
+<pre>export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo'
+export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar'</pre>
+
+ <p>(Obviously, replace those with actual values.)</p>
+
+ <p>Then, you can use</p>
+
+<pre>aws_upload("bucket_name","filename")</pre>
+
+ <p>To easily upload public-access files. This method will automatically connect to Amazon S3 for you, if your keys are defined in your environment variables. It also writes the resulting Amazon URL to your clipboard, if you're on OS X, so you can easily share the file with others. Note that you have to create the initial buckets manually - see <a href="http://amazon.rubyforge.org" title="AWS::S3 - Ruby Library for Amazon Simple Storage Service (S3)">amazon.rubyforge.org</a> for details on that.</p>
+
+ <p>A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file:</p>
+
+<pre>def my_bucket_name(filename)
+ aws_upload("my_default_bucket",filename)
+end</pre>
+
+ <h4>Command-line Amazon S3 upload script</h4>
+
+<p>Utility Belt also includes <code>amazon</code>, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is:</p>
+
+<pre>amazon -b my_bucket_name filename other_filename</pre>
+
+<p>(For any arbitrary number of filenames.)</p>
+
+<p>Anytime you want to upload a file to your default bucket on S3, for example, the "images" bucket for your blog - or the "mp3" bucket if you're running a blog like Projectionist - all you have to do is</p>
+
+<pre>amazon -b blog_files some_file.name</pre>
+
+<p>Or</p>
+
+<pre>amazon --bucket blog_files some_file.name</pre>
+
+<p>And you're good to go. Of course, if that were too many characters to type, you could always take it one step further with a shell script. For instance, in bash:</p>
+
+<pre>alias b1="amazon --bucket my_main_bucket $1"
+alias b2="amazon --bucket my_other_bucket $1"</pre>
+
+<p>And then you would only have to type:</p>
+
+<pre>b1 file.name</pre>
+
+<p>And of course tab completion will handle all the typing of the file name, assuming you choose your file names deliberately ahead of time to make tab completion effective, in which case all you have to type is "b1 f[tab]" and bam.</p>
+
+ <h4>Command-line Google shortcut (OS X only)</h4>
+
+<p>To pop open a new window in your default browser with Google search results for a given search term, do:</p>
+
+<pre>google "any given term"</pre>
+
+<p>For one-word terms, you can omit the quotes:</p>
+
+<pre>google term</pre>
+
+<p>If you already have the search term in your clipboard, you can just type:</p>
+
+<pre>google</pre>
+
+<p>(The last approach is useful for unusual command-line error messages.)</p>
+
+ <h4>Auto-indentation</h4>
+
+ <p>Just type as normally. This just enables built-in but underused functionality in IRB. (The IRB default auto-indentation isn't perfect, but it clobbers the living hell out of no indentation at all.)</p>
+
+ <h4>_ special variable (like Unix shell var !!)</h4>
+
+ <p>More activation of built-in but underused functionality in IRB. _ functions like !! in Unix, with one subtle difference. Instead of re-issuing the previous command in your history, it gives you the last result of evaluating a command. This means when you start a new IRB session, _ won't go to your history, it'll just give you nil, and it means that some commands can't be repeated exactly. Nine out of ten times, however, it's pretty much the same thing.</p>
+
+ <p>Note that when combined with the h! in the command history code, you basically have two synonyms for !! here. Neither one is an exact replica, but between the two of them, you should have what you need.</p>
+
+ <h4>Extremely basic themes for Wirble syntax coloring</h4>
+
+ <p>Utility Belt incorporates <a href="http://pablotron.org/software/wirble/" title="Pablotron: Wirble">Wirble</a> as a dependency. Wirble provides syntax coloring. Utility Belt allows you to choose between two syntax coloring themes: Wirble's default, and an alternate color set for terminals with light backgrounds. The default theme is enabled by default (duh), but if you have a terminal with a light background, you can enable the light-background theme just by putting the following line of code in your .irbrc:</p>
+
+<pre>UtilityBelt::Themes.background(:light)</pre>
+
+ <p>To revert back to the default, just use this:</p>
+
+<pre>UtilityBelt::Themes.background(:dark)</pre>
+
+<p>To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble.</p>
+
+ <h4>Pascal/JavaScript-style "with" statement</h4>
+
+ <p>I use this with RSpec's spec_helper. Instead of:</p>
+
+<pre>Spec::Runner.configure do |config|
+ config.use_transactional_fixtures = true
+ config.use_instantiated_fixtures = false
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures'
+ config.mock_with :flexmock
+end</pre>
+
+ <p>I do this:</p>
+
+<pre>Spec::Runner.configure do |config|
+ with(config) do
+ use_transactional_fixtures = true
+ use_instantiated_fixtures = false
+ fixture_path = RAILS_ROOT + '/spec/fixtures'
+ mock_with :flexmock
+ end
+end</pre>
+
+ <p>Note however that this blew up once and I have no idea why. Caveat emptor, et cetera.</p>
+
+ <h4>String#to_proc</h4>
+
+ <p>Syntactic sugar for functional programming. (<a href="http://weblog.raganwald.com/2007/10/stringtoproc.html" title="String#to_proc">More detail here</a>.) Rails' Symbol#to_proc is also included.</p>
+
+<pre>(1..3).map(&amp;&apos;*2&apos;) =&gt; [2, 4, 6]
+(1..3).map(&amp;&apos;[-1, _, 0]&apos;) =&gt; [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]]
+(1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;[2]&apos;) =&gt; [2, 4, 6]
+(1..5).select(&amp;&apos;&gt;2&apos;) =&gt; [3, 4, 5]
+(1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;.call(2)&apos;) =&gt; [2, 4, 6]
+[5].map(&amp;&quot;(1.._).inject(&amp;&apos;*&apos;)&quot;) =&gt; [120]</pre>
+
+ <h4>Add and subtract Hashes with + and -</h4>
+
+<pre>{:a =&gt; :b} + {:c =&gt; :d} = {:a =&gt; :b, :c =&gt; :d}
+{:a =&gt; :b, :c =&gt; :d} - {:c =&gt; :d} = {:a =&gt; :b}
+{:a =&gt; :b, :c =&gt; :d} - :c = {:a =&gt; :b}</pre>
+
+ <p>You could already do this with Arrays; now you can do it with Hashes as well. (I was kinda surprised the first time I tried to do this and realized I'd have to write it myself.)</p>
+
+
+ <h4>Grammatically-correct is_an? method - no more "is_a? Array" statements</h4>
+
+<pre>&gt;&gt; [].is_an? Array
+#=&gt; true</pre>
+
+ <p>Most people don't care, but personally, "is_a? Array" drives me completely insane.</p>
+
+ <h4>Object#not</h4>
+
+ <p>Replace this:</p>
+
+<pre>if !response.incomplete? &amp;&amp; !response.invalid? &amp;&amp; response.total &gt; 0</pre>
+
+ <p>With this:</p>
+
+<pre>if response.not.incomplete? &amp;&amp; response.not.invalid? &amp;&amp; response.total &gt; 0</pre>
+
+ <p>Syntactic sugar for boolean conditions. (<a href="http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html" title="Jay Fields Thoughts: Ruby: Adding a "not" method for readability">More detail here</a>.)</p>
+
+ <h4>One-character exit command</h4>
+
+<pre>x</pre>
+
+ <p>Because life is too short to type whole words.</p>
+
+
+ </div>
+
+ <div id="footer">
+ <p>Copyright &copy; 2007 Giles Bowkett | Design by <a href="http://andreasviklund.com">Andreas Viklund</a>.</p>
+ </div>
+ </div>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.