Ruby Pages

Dot Net Perls has example pages for many languages, with explanations and code side by side (for easy understanding).


Test and benchmark iterators. Use times, upto, downto, step and each in programs.Ruby Iterator: Times, Step Loops

2D array.

Use 2D arrays and jagged arrays. Nest arrays and access subarrays.Ruby 2D Array Examples


Use arrays: add elements, change elements and test arrays with loops and iterators.Ruby Array Examples


Use the case statement. Match values, and ranges of values, with this statement.Ruby Case Examples: Ranges, Strings and Regexp


Use the console window. Call the puts, p, print and stdin.readline methods.Ruby Console: Puts, Print and stdin


Cast and converts types: use methods to convert strings, arrays and hashes.Ruby Convert Types: Arrays and Strings


Use the DateTime class. Compute and manipulate dates and times.Ruby DateTime Examples: require date


Handle exceptions. Use begin, rescue and ensure to enter protected regions.Ruby Exception Examples: Begin and Rescue


Handle files: open a file with and sequentially read in each line until eof.Ruby File Handling: File and IO Classes


Use the format string syntax. See examples for formatting values in many ways.Ruby Format String Examples


Use the Hash class to store keys and values. Hash enables fast lookups.Ruby Hash Examples


Use the if-statement, elsif and else. See the unless statement.Ruby If Examples: Elsif, Else and Unless


Review a list of keywords in Ruby. These keywords are used in nearly all programs.Ruby Keywords


Use mathematical functions like floor, ceil and truncate. Compute square roots.Ruby Math Examples: floor, ceil, round and truncate


Test values against nil, with an if, to avoid errors like NoMethodError.Ruby Nil Value Examples: NoMethodError


Use numbers and the zero and eql methods. Convert strings into Integers and Floats.Ruby Number Examples: Integer, Float, zero and eql

Rand, random numbers.

Generate random numbers with rand. Use srand to seed a random stream.Ruby Random Number Generator: rand, srand


Use the Regexp class, which processes text. Call the match and split methods.Ruby Regexp Match Method

Remove duplicates.

Use the uniq method to remove duplicate elements from arrays with minimal code.Ruby Remove Duplicates From Array


Use the set collection. Add elements to sets and use include, merge and subset.Ruby Set Examples


Use the sort method. Sort with blocks, sort in descending order and sort in-place.Ruby Sort Arrays (Use Block Syntax)


Call the split method to separate strings. Use string and regular expression delimiters.Ruby Split String Examples


Use strings: create literals, manipulate strings and use each char and each line.Ruby String Examples (each char, each line)

Sub, gsub.

Use sub and gsub to replace strings. Regular expressions are used for complex replacements.Ruby Sub, gsub: Replace String


Get substrings with ranges and indexes. Regular expressions can be used to get substrings.Ruby Substring Examples


Loop over ranges of numbers. See the while-loop, until-loop and other loops.Ruby While, Until and For Loop Examples
Dot Net Perls
© 2007-2019 Sam Allen. All rights reserved. Written by Sam Allen,