Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Ruby collections and strings - some new examples

From yesterday's Ruby course - a whole set of new examples on Ruby collections - arrays (which are ordered lists) and hashes (which are unordered). In other words, you look somethng up in an array by its position number, whereas you look something up in a hash based on its unique key, and the way it's implemented, you cannot sort those keys - if you try, you get an array or arrays of two elements returned!

[example] - Sorting an array and iterating through it in various ways

[example] - Using an anonymous array to swap over two variables easily

[exampe] - Combining arrays with "and" and "or"

[example] - sorting a hash - (you can't, but this shows how to get the same effective result!)

[example] - multidimensional structures in Ruby - a hash or arrays in this case


Here are some other examples from yesterday too - string handling and exceptions:

[example] - lots of ways of defining and handling strings

[example] - cleaning up strings of text that are user input using string methods and regular expressions

[example] Using a constant to turn debug mode on and off - also a very good example of reading from and processing a file in Ruby

(written 2010-02-03 07:28:50)

 
Associated topics are indexed under
R107 - Collections (Arrays and Hashes) in Ruby
  [2618] What are Ruby Symbols? - (2010-02-02)
  [2606] Sorting arrays and hashes in Ruby - (2010-01-30)
  [2291] Collection objects (array and hash) in Ruby - (2009-07-16)
  [991] Adding a member to a Hash in Ruby - (2006-12-16)

R109 - Ruby - Strings and Regular Expressions
  [2623] Object Oriented Ruby - new examples - (2010-02-03)
  [2614] Neatly formatting results into a table - (2010-02-01)
  [2608] Search and replace in Ruby - Ruby Regular Expressions - (2010-01-31)
  [2295] The dog is not in trouble - (2009-07-17)
  [2293] Regular Expressions in Ruby - (2009-07-16)
  [1891] Ruby to access web services - (2008-11-16)
  [1887] Ruby Programming Course - Saturday and Sunday - (2008-11-16)
  [1875] What are exceptions - Python based answer - (2008-11-08)
  [1588] String interpretation in Ruby - (2008-03-21)
  [1305] Regular expressions made easy - building from components - (2007-08-16)
  [1195] Regular Express Primer - (2007-05-20)
  [987] Ruby v Perl - interpollating variables - (2006-12-15)
  [986] puts - opposite of chomp in Ruby - (2006-12-15)
  [970] String duplication - x in Perl, * in Python and Ruby - (2006-12-07)

R111 - Ruby - Exceptions.
  [2622] Handling unusual and error conditions - exceptions - (2010-02-03)
  [2620] Direct access to object variable (attributes) in Ruby - (2010-02-02)
  [2615] String to number conversion with error trapping in Ruby - (2010-02-01)

R118 - Ruby Sources and Resources
  [2610] Cheat Sheet - what do you need for Ruby on Rails? - (2010-01-31)
  [550] 2006 - Making business a pleasure - (2006-01-01)

R106 - Input and Output in Ruby
  [2290] Opening and reading files - the ruby fundamentals - (2009-07-16)
  [1587] Some Ruby programming examples from our course - (2008-03-21)


Back to
Direct access to object variable (attributes) in Ruby
Previous and next
or
Horse's mouth home
Forward to
Handling unusual and error conditions - exceptions
Some other Articles
Both feet on the same pavement
Skyline and looking up in London
Ruby collections and strings - some new examples
Passing code to procedures and yield in Ruby
Comparing floating point numbers - a word of caution and a solution
Defining a static method - Java, Python and Ruby
2662 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2010: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 344596 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho