You can throw an error with raise DeadPlayerError. Ruby distinguishes errors, from which a program can recover, and other kinds of exceptions, which leave the program in an invalid state and therefore it must stop.

Point = Struct.new :x, :y, :z

Creates a class with getters and setters for the given attributes. Notice that:

Member attributes of a class are always private (or protected, as they are inherited). Thus, the dot only sends methods and doesn’t directly access attributes.

Methods can be defined in a do ... end block. You should consider defining a class if you want to add them.

New objects are created with Point.new.

Iteration and data structures

puts%w[such elegant wow].each_with_index.map{|w,i|"#{i}. #{w}"}

Walks through the array, obtains an array of strings index. element and prints it on stdout. Notice that:

%w[] splits a list of words by spaces and returns an array.

each_with_index iterates giving each element and its index in the collection.

map applies a function on each element of a collection and returns the result.

{...} o do ... end denote blocks, structures of code which are passed to methods in order to be ran from them. Blocks can receive parameters between bars |a, b|.

Assuming the .neighborhood returns a collection of possible solutions and their performance (fitness), this finds the first one which improves the current solution. Actual use: https://git.io/vPxQ6. Notice that:

detect receives a predicate and returns the first ellement of the collection which verifies it.

If you want to get the best solution in the neighborhood instead, you can use max_by.

There is a huge list of iteration methods available in any Ruby collection class:
Enumerable

I/O

open(DATA.read,"w").writeIO.read($0).gsub(/^#' /,"")

This snippet reads itself (as in, the own program running), uncomments lines marked with #' and passes the result as input to the program started by Kernel#open. Notice that:

$0 is the name of the current program/script.

gsub performs global sustitution

Kernel#open opens read/write pipes with other processes when the “filename” looks like "|program_name".

The catch The program is hidden in the data section of the original script: