Reading "The Ruby Programming Language—Chapter 1. Introduction"
Here are my notes on “Chapter 1. Introduction” of The Ruby Programming Language by David Flanagan and Yukihiro Matsumoto.
The first impression of Ruby: dynamic, a complex but expressive grammar, pure object-oriented, and metaprogramming.
Notes on Each Section
1.1 A Tour of Ruby
Ruby is pure object-oriented.
It means that every value—even a number or a boolean—is an object. It means that they have methods, for example,1 2 3 4 5
> 1.class # => Integer > 0.0.class # => Float > true.class # => TrueClass > false.class # => FalseClass > nil.class. # => NilClass
Some special methods can be used as iterators.
For example,1 2
3.times { print "Ruby! " } # Ruby! Ruby! Ruby! 1.upto(9) { |x| print x } # 123456789
Ruby is expression-oriented.
It means that statements in Ruby are also expressions, for example,1
minimum = if x < y then x else y end
1.2 Try Ruby
Use ruby to execute a program file. Use irb to run an interactive Ruby interpreter. Use ri to read docs. Use gem to install Ruby packages.
1.3 About This Book
This book takes a bottom-up approach to Ruby, but introducing concepts in a rigorously linear way is impossible since a programming language is not a linear system.
1.4 A Sudoku Solver in Ruby
This section gives us a short to medium-length program—Sodoku solver—to demonstrate a number of features of Ruby, but I don’t have patience to read it now.
