Languages
Ruby
Enumerable, hashes and blocks for concise Ruby programs.
Values and collections
name = "Ada"Bind a stringnames = ["Ada", "Lin"]Create an arrayuser = { name: "Ada", id: 1 }Create a symbol-keyed hashuser.fetch(:role, "reader")Read with an explicit fallbackEnumerable
[1, 2, 3].map { |n| n * 2 }Transform elements[1, 2, 3].select { |n| n.odd? }Filter by a predicate[1, 2, 3].sumSum numeric elementsnames.each_with_index { |name, i| puts "#{i}: #{name}" }Iterate with positionsMethods and files
def add(a, b); a + b; endReturn the final expression of a methodFile.read("notes.txt")Read a file into a stringFile.foreach("notes.txt") { |line| puts line }Iterate through linesruby -c app.rbCheck source syntax