Ruby¶
Ruby is a delightful programming language designed for programmer happiness 💖.
Yukihiro Matsumoto once presented How Emacs Changed My Life (PDF) which goes into how Emacs and emacs-lisp influenced Matz and the design of the Ruby programming language. Unfortunately, it seems there is not video recording of it. Here’s the Slideshare link for the presentation.
I Love Ruby free, online book (rendered in Asciidoctor) by Karthikeyan A K.
Nice tools:
Ruby Concepts and Ideas¶
The name of the language is spelled Ruby (not RUBY or ruby) because it is a proper noun (therefore, the first letter is capitalized).
ruby
is the name of the program we use to run Ruby programs, likeruby -w fib.rb
.A mix-in (also spelled mix in) is the including of a module inside a class. We say things like “The Enumerable mix-in module provides…”. See Ruby doc on modules.
Bits and Bytes of Syntax Suggar¶
Hash Values¶
We can get all the values of a hash by doing this:
>> { one: 1, two: 2 }.map(&:last)
=> [1, 2]
Which is similar to doing hash.values
Map and Hash to Proc to Get Values¶
>> h = { one: 1, two: 2 }
>> [:one, :two].map(&h)
=> [1, 2]
With an array of keys, we map over those keys, and turn the hash into a proc😲!
Saw this first in a solution for resistor color duo exercism challenge.
If we define to_proc
we can use this trick for any object.
Hash Transform Values and &:next to_proc¶
>> {one: 1, two: 2}.transform_values(&:next)
=> {:one=>2, :two=>3}
- Unit Tests | Ruby
- RSpec | Ruby
- Scope | Ruby
- HackerRank Ruby Tutorial
- Hello World
- self
- methods
- Accessing Array Elements
- Modifying Arrays
- Filtering Arrays
- Hashes
- unless
- loop, break if
- group_by
- Arrays
- Currying
- Lazy
- Blocks
- Procs
- Lambdas
- Closures
- Currying and Partial Application
- Arguments and Splat Operator
- Keyword Arguments
- String Indexing
- String Iteration
- String Methods I
- String Methods II
- Enumerables ‘each_with_index’
- rot13, map, collect
- Enumerable reduce, inject
- Enumerables any, all, none, find
- String Encoding
- Methods Intro
- Method Arguments
- Ruby Enumerable Intro
- Bundler | Ruby
- RVM | Ruby
- Pry | Ruby