Posted about 6 years ago. Visible to the public.

Ruby basics [2d]

Ruby is the programming language we use almost exclusively.

Goals

  • Be able to read and write simple Ruby programs.
  • Gain an understanding of the following concepts:
    • Basic datatypes: Strings, Numbers, Booleans, Arrays, Hashes
    • Basic language constructs: if, each, case, break...
    • Regular expressions
    • Functions: def, return
    • Errors and raise
    • Object orientation
      • Classes
      • Class methods vs instance methods (def self.method vs. def method)
      • Inheritance
      • Modules and include
    • Code blocks
    • Input and Output

Resources

Look at these

References

Exercises

Word count

Write a small ruby programm cw that accepts a filename, counts the number of
words, lines and paragraphs, and outputs the result.

Hints:

  • Find out about ARGV.
  • Look up File on apidock.
  • Learn about regular expressions.

random_each

Give Array a new method .random_each, that loops randomly through the entries.
I want to be able to say

Copy
[1, 2, 3, 4, 5].random_each do |value| puts value end

And get

Copy
4 2 1 5 3

Hints:

Owner of this card:

Avatar
Henning Koch
Last edit:
5 months ago
by Henning Koch
Posted by Henning Koch to makandra Curriculum
This website uses short-lived cookies to improve usability.
Accept or learn more