Lecture notes 1 - Readings for this topic Read Chapter 1 of The Ruby Programming Language then skim Chapters 2-7 to get a feel for the operators

Lecture notes 1 - Readings for this topic Read Chapter 1 of...

This preview shows page 1 - 3 out of 7 pages.

Readings for this topic: Read Chapter 1 of The Ruby Programming Language , then skim Chapters 2-7 to get a feel for the operators, statements, and class facilities. You can read more of the details as you are working on the projects. Read Sections 8.9 and 8.10 of The Ruby Programming Language . You will need this information for Project #2. Ruby basics: Scripting language (more dynamic, interpreted than Java) Very dynamic, flexible: metaprogramming facilities (write programs that write programs) Pure object oriented: absolutely everything is an object Large language, many features Simple code example: sum = 0 i = 1 while i <= 10 do sum += i*i i = i + 1 end puts "Sum of squares is #{sum}\n" Syntactic differences from Java and C: No variable declarations Newline terminates statements (semicolons OK too) do...end instead of {...} . Optional parentheses in method invocation Built-in datatypes: Numbers: Integer (Fixnum and Bignum) Float Complex BigDecimal Rational Strings: Single quotes (only a few backslash sequences) Double quotes (lots of backslash sequences)
%q (like ''), %Q (like ""): s1 = %q(String contains quotes: '"') s2 = %Q|More quotes ("") and subs: #{x}| Here documents: doc = <<END First line Second line END Symbols: Notation: :foo A string constant, more efficient in many situations Typically used for unique identifiers such as variable and method names, hash keys, etc.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture