Difference between revisions of "Ruby on Rails"

From Hawk Wiki
Jump to: navigation, search
Line 6: Line 6:
  
 
<h3>nil?, empty? and blank?</h3>
 
<h3>nil?, empty? and blank?</h3>
.nil? can be used on any object and is true if the object is nil.<br>
+
<code>
 +
.nil? can be used on any object and is true if the object is nil.
  
.empty? can be used on strings, arrays and hashes and returns true if:<br>
+
.empty? can be used on strings, arrays and hashes and returns true if:
  
String length == 0<br>
+
String length == 0
Array length == 0<br>
+
Array length == 0
Hash length == 0<br>
+
Hash length == 0
Running .empty? on something that is nil will throw a NoMethodError.<br>
+
Running .empty? on something that is nil will throw a NoMethodError.
  
.blank? will operate on any object<br>
+
.blank? will operate on any object
nil.blank? == true<br>
+
nil.blank? == true
false.blank? == true<br>
+
false.blank? == true
[].blank? == true<br>
+
[].blank? == true
{}.blank? == true<br>
+
{}.blank? == true
"".blank? == true<br>
+
"".blank? == true
5.blank? == false<br>
+
5.blank? == false
"  ".blank? == true<br>
+
"  ".blank? == true
"  ".empty? == false<br>
+
"  ".empty? == false
 +
</code>

Revision as of 18:09, 16 September 2013

Tutorials

Beginner's tutorial
http://allaboutruby.wordpress.com/2006/01/09/installing-rails-on-windows-step-by-step-tutorial/
Ruby in 20 minutes
http://www.ruby-lang.org/en/documentation/quickstart/

nil?, empty? and blank?

.nil? can be used on any object and is true if the object is nil.

.empty? can be used on strings, arrays and hashes and returns true if:

String length == 0 Array length == 0 Hash length == 0 Running .empty? on something that is nil will throw a NoMethodError.

.blank? will operate on any object nil.blank? == true false.blank? == true [].blank? == true {}.blank? == true "".blank? == true 5.blank? == false " ".blank? == true " ".empty? == false