<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Ruby on Rails Notes &#187; email</title> <atom:link href="http://railsnotes.com/tag/email/feed/" rel="self" type="application/rss+xml" /><link>http://railsnotes.com</link> <description>A code-heavy brain dump of stuff I come across working on Ruby on Rails projects including Models, ActiveRecord, Views, Controllers, RESTful rails, deployment, server stuff, etc.</description> <lastBuildDate>Sun, 29 Aug 2010 23:45:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>ljust method for Ruby String</title><link>http://railsnotes.com/357-ljust-method-for-ruby-string/</link> <comments>http://railsnotes.com/357-ljust-method-for-ruby-string/#comments</comments> <pubDate>Thu, 30 Apr 2009 03:10:09 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[email]]></category> <category><![CDATA[ljust]]></category> <category><![CDATA[rjust]]></category> <category><![CDATA[ruby]]></category> <category><![CDATA[string]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=357</guid> <description><![CDATA[Something interesting I discovered today while working on an email is the ljust &#38; rjust methods (think left &#38; right justified) for Ruby strings. What it does is it makes sure that your string has at least a certain number of characters and if it doesn&#8217;t it adds some characters. Here&#8217;s a small code snippet from [...]]]></description> <content:encoded><![CDATA[<p></p><p>Something interesting I discovered today while working on an email is the ljust &amp; rjust methods (think left &amp; right justified) for Ruby strings. What it does is it makes sure that your string has at least a certain number of characters and if it doesn&#8217;t it adds some characters. Here&#8217;s a small code snippet from the rdocs that is pretty self explaining:</p><pre>"hello".ljust(4)            #=&gt; "hello"
"hello".ljust(20)           #=&gt; "hello               "
"hello".ljust(20, '1234')   #=&gt; "hello123412341234123"</pre><pre>"hello".rjust(4)            #=&gt; "hello"
"hello".rjust(20)           #=&gt; "               hello"
"hello".rjust(20, '1234')   #=&gt; "123412341234123hello"</pre><p>This is useful when sending emails with Rails that are plain text emails. It can help you align things that look like columns, like this:</p><pre>
INVOICE
----------------------------------------------------------

Bill to:
&lt;%= @account.user.name %&gt;

Description                                          Price
----------------------------------------------------------
&lt;%= (@product.name).ljust(36) %&gt; &lt;%= number_to_currency(@product.amount).rjust(21) %&gt;

If you have any questions about this invoice, please contact
&lt;%= AppConfig['from_email'] %&gt;.

Thank you for your business!
</pre><p>This would produce an email that might look like this:</p><pre>
INVOICE
----------------------------------------------------------

Bill to:
Michael Jordan

Description                                          Price
----------------------------------------------------------
Nike Air shoes                                        $150

If you have any questions about this invoice, please contact
support@nike.com

Thank you for your business!</pre></pre> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/357-ljust-method-for-ruby-string/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 4/16 queries in 0.030 seconds using disk

Served from: railsnotes.com @ 2010-09-09 07:30:13 -->