Some Methods in Ruby
What have I found out so far?
There are many methods in string like the reverse that gives a backwards version of a string. length that tells us the number of characters (including spaces) in the string. upcase changes every lowercase letter to uppercase, and downcase changes every uppercase letter to lowercase. swapcase switches the case of every letter in the string, and finally, capitalize is just like downcase, except that it switches the first character to uppercase (if it is a letter).
Update: (11:10 hrs) I came across another construct, the do end. I shall show an example of this when I talk about arrays.
Technorati Tags: Some Methods in Ruby
Blogs linking to this article
- Definition of Ruby
- Ruby Windows Installer
- Interactive Ruby - Open a new DOS window and type irb --simple-prompt A prompt appears as >>
- Run a Ruby program by typing ruby hello.rb
- Learnt some features of Ruby like comments, naming rules, variables, constants, strings etc.
- Various Text Editors/IDEs like SciTE, NotePad2
- Constructs like the if else and while
# gets and chompchomp is a string method and gets returns back a string. You must have realised that gets returns a string and a '\n' character, while chomp removes this '\n'.
puts "In which city do you stay?"
city = gets.chomp
puts "The city is " + city
There are many methods in string like the reverse that gives a backwards version of a string. length that tells us the number of characters (including spaces) in the string. upcase changes every lowercase letter to uppercase, and downcase changes every uppercase letter to lowercase. swapcase switches the case of every letter in the string, and finally, capitalize is just like downcase, except that it switches the first character to uppercase (if it is a letter).
Update: (11:10 hrs) I came across another construct, the do end. I shall show an example of this when I talk about arrays.
First Post | Previous | Next
Technorati Tags: Some Methods in Ruby
Blogs linking to this article
0 Comments:
Post a Comment
<< Home