Benx Shen's personal annotations on this page
-
h = {"hash?" => "yep, it's a hash!", "the answer to everything" => 42, :linux => "fun for coders."}
puts "Stringy string McString!".class
puts 1.class
puts nil.class
puts h.class
puts :symbol.classSee? Everything is an object.
-
If I kept doing this, array2 wouldn't hold any elements. I can check for this condition by calling the empty? method. For example, the following bit of code moves all the elements from one array to another:
array1 << array2.pop until array2.empty?
-
Time for the last three:
string1 = 451.to_s
string2 = 98.6.to_s
int = 4.5.to_i
float = 5.to_fto_s converts floats and integers to strings. to_i converts floats to integers. to_f converts integers to floats. There you have it. All the data types of Ruby in a nutshell.
This link has been bookmarked by 1 people . It was first bookmarked on 24 Oct 2009, by Benx Shen.
-
-
h = {"hash?" => "yep, it's a hash!", "the answer to everything" => 42, :linux => "fun for coders."}
puts "Stringy string McString!".class
puts 1.class
puts nil.class
puts h.class
puts :symbol.classSee? Everything is an object.
-
If I kept doing this, array2 wouldn't hold any elements. I can check for this condition by calling the empty? method. For example, the following bit of code moves all the elements from one array to another:
array1 << array2.pop until array2.empty?
- 1 more annotations...
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.