<?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; ruby</title> <atom:link href="http://railsnotes.com/tag/ruby/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> <item><title>[Link] Ruby Basics</title><link>http://railsnotes.com/284-link-ruby-basics/</link> <comments>http://railsnotes.com/284-link-ruby-basics/#comments</comments> <pubDate>Fri, 24 Apr 2009 20:50:36 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[basics]]></category> <category><![CDATA[ruby]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=284</guid> <description><![CDATA[Peter Cooper posted a new blog entry that links to 17 Videos Covering Basic Ruby Techniques. These videos cover the basics and may not have any surprising new info but it&#8217;s nice to review the basics from time to time. Take a look.]]></description> <content:encoded><![CDATA[<p></p><p>Peter Cooper posted a new blog entry that links to <a
href="http://www.rubyinside.com/17-videos-covering-basic-ruby-techiques-1685.html">17 Videos Covering Basic Ruby Techniques</a>. These videos cover the basics and may not have any surprising new info but it&#8217;s nice to review the basics from time to time. Take a look.</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/284-link-ruby-basics/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Integer to Floating Point in Ruby</title><link>http://railsnotes.com/84-integer-to-floating-point-in-ruby/</link> <comments>http://railsnotes.com/84-integer-to-floating-point-in-ruby/#comments</comments> <pubDate>Fri, 06 Feb 2009 02:34:29 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Ruby & Rails Core]]></category> <category><![CDATA[fixnum]]></category> <category><![CDATA[float]]></category> <category><![CDATA[integer]]></category> <category><![CDATA[ruby]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=84</guid> <description><![CDATA[Okay, this is something weird I ran into today. If you do 3/4 in ruby, it will give you back 0. Basically it has to do with the fact that both are integers. If you want to divide two numbers and get back a decimal number (aka floating point number), you&#8217;ll need at least one [...]]]></description> <content:encoded><![CDATA[<p></p><p>Okay, this is something weird I ran into today. If you do 3/4 in ruby, it will give you back 0. Basically it has to do with the fact that both are integers.</p><p>If you want to divide two numbers and get back a decimal number (aka floating point number), you&#8217;ll need at least one of them to be a floating point.</p><p>How do you turn an integer into a floating point? Use .to_f or * 1.0 or =+ 0.0</p><p>Taking the above example, 3/4.to_f =&gt; 0.75</p><p>Now, if you want to limit how many numbers show up after the decimal point, you&#8217;ll need to use the sprintf function. Here are a few examples:</p><p>===============</p><p>&gt;&gt; sprintf(&#8216;%0.1f&#8217;, (3.to_f/8))</p><p>=&gt; &#8220;0.4&#8243;</p><p>&gt;&gt; sprintf(&#8216;%0.2f&#8217;, (3.to_f/8))</p><p>=&gt; &#8220;0.38&#8243;</p><p>&gt;&gt; sprintf(&#8216;%0.3f&#8217;, (3.to_f/8))</p><p>=&gt; &#8220;0.375&#8243;</p><p>&gt;&gt; sprintf(&#8216;%0.4f&#8217;, (3.to_f/8))</p><p>=&gt; &#8220;0.3750&#8243;</p><p>===================</p><p>Now, if you need to format numbers instead a view, you should check out the number_to &amp; number_with helpers.</p><p>Thanks to <a
href="http://flow.handle.it/" target="_blank">Jason King</a> for telling me about all this.</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/84-integer-to-floating-point-in-ruby/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Does Rails Scale?</title><link>http://railsnotes.com/13-does-rails-scale/</link> <comments>http://railsnotes.com/13-does-rails-scale/#comments</comments> <pubDate>Mon, 29 Sep 2008 18:22:51 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Scaling Rails]]></category> <category><![CDATA[debate]]></category> <category><![CDATA[ruby]]></category> <category><![CDATA[scale]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=13</guid> <description><![CDATA[Trimmed down version of a recent conversation on the #rubyonrails IRC channel: halogenandtoast: I&#8217;m not trying to start anything, but there&#8217;s always the discussion that rails doesn&#8217;t scale, I kind of disagree with this. php suffers from all the same problems rails seems to. most of the major problems all apps suffer from is bad [...]]]></description> <content:encoded><![CDATA[<p></p><p><strong>Trimmed down version of a recent conversation on the #rubyonrails IRC channel:</strong></p><p>halogenandtoast: I&#8217;m not trying to start anything, but there&#8217;s always the discussion that rails doesn&#8217;t scale, I kind of disagree with this. php suffers from all the same problems rails seems to. most of the major problems all apps suffer from is bad database management. Does anybody know a little more about this. i.e. does rails scale, if not why?</p><p>wmoxam: ugh, really? Do we need another &#8220;does it scale&#8221; discussion?</p><p>melvinram:  halogenandtoast: what kind of an app are you working on/building?</p><p>halogenandtoast:  wmoxam: I haven&#8217;t had a discussion about it yet, but I wanted to be educated when people say, we can&#8217;t use rails it doesn&#8217;t scale. If I&#8217;m uninformed then I come off stupid and they end up feeling like they are right.</p><p>melvinram:  i can&#8217;t confidently say it does scale as I haven&#8217;t built a system that has needed to scale yet &#8230; but BaseCamp seems to stay up 99% of the time and they use multiple servers so it is possible and whoever says its not hasn&#8217;t thought it through.</p><p>wmoxam:  what kind of projects do you guys do where you work?</p><p>halogenandtoast:  but then they use cakephp, sigh. I think everyone&#8217;s poster child for the scaling problem was twitter, but once pivital labs stepped in they eliminated almost all of their problems</p><p>wmoxam:  but twitter isn&#8217;t a traditional web app</p><p>halogenandtoast:  there are traditional web apps?</p><p>wmoxam:  sure. most of &#8216;em are CRUD. twitter is a massive messaging system with a web interface tacked on the front.</p><p>melvinram:  what I don&#8217;t get is why twitter is so different than FaceBook&#8217;s status feature? Isn&#8217;t it just a CRUD function?</p><p>wmoxam:  no. it gets a lot of sms usage, and was designed to work without (much) lag. where a facebook status update might not be visible to your friends right away.</p><p>melvinram:  hmm it still doesn&#8217;t fully make sense&#8230; as sms interface is just CRUD from different input method &#8230; n FaceBook is real time for me&#8230; but i&#8217;m guessing it&#8217;s because i don&#8217;t fully understand the dependencies involved. i&#8217;m not worrried about it&#8230; i&#8217;m not building a messeging system :D</p><p>wmoxam:  messaging systems get complicated, especially when you&#8217;re trying to do things in real time. it&#8217;s my understanding that Mysql was at the heart of twitter&#8217;s problems. basically they we&#8217;re using it where they should have been using queue instead</p><p>melvinram:  ya that make sense that it would cause probs. I&#8217;m going to trim down the conversation on Does Rails Scale? and post it on my new blog (http://www.railsnotes.com)</p><p>wmoxam:  don&#8217;t trust me on my twitter musings. I heard it all via third party</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/13-does-rails-scale/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 2/16 queries in 0.044 seconds using disk

Served from: railsnotes.com @ 2010-09-10 05:04:30 -->