Introduction
Ruby was designed with one unusual priority: the happiness of the programmer. Its creator, Yukihiro Matsumoto, believed code should be a joy to read and write, and that philosophy shaped a language that often reads like plain English. Ruby is best known through Ruby on Rails, the web framework that launched companies like Shopify, GitHub, and Airbnb β but the language itself is worth learning for its ideas alone.
Everything is an object
In Ruby, there are almost no special cases: numbers, strings, even true and false are objects with methods you can call.
5 . times { | i | puts "Hello #{ i } " } # Hello 0 # Hello 1 # Hello 2 # Hello 3 # Hello 4 "hello" . upcase # => "HELLO" [ 3 , 1 , 2 ]. sort # => [1, 2, 3]
Enter fullscreen mode
Exit fullscreen mode
5.times calls a method on the number 5 itself, and the block { |i| ... } is a chunk of code passed to that method β Ruby's most distinctive feature.β¦