This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
# Returns a proc which calls [] with the array's contents as arguments | |
# | |
# ====Usage | |
# [[1, 2], [3, 4], [5, 6]].map(&[0]) | |
# # => [1, 3, 5] | |
# | |
# [{ hello: 'world' }, { hello: 'sun', goodbye: 'moon' }].map(&[:hello]) | |
# # => ['world', 'sun'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
class Foo | |
def self.bar(first, second, third) | |
err_msg = '%s cannot be nil' | |
raise ArgumentError, err_msg % 'first' unless first | |
raise ArgumentError, err_msg % 'second' unless second | |
raise ArgumentError, err_msg % 'third' unless third | |
"#{first} #{second} #{third}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'matrix' | |
NEIGHBOUR_RELATIVE_COORDS = | |
[[-1, -1], [-1, 0], [-1, 1], | |
[ 0, -1], [ 0, 1], | |
[ 1, -1], [ 1, 0], [ 1, 1]] | |
# Init matrix | |
# true = alive, false = dead | |
matrix = Matrix.build(35, 45) { [true, false].sample } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Game | |
WINNING_PATTERNS = [ | |
[0, 1, 2], | |
[3, 4, 5], | |
[6, 7, 8], | |
[0, 3, 6], | |
[1, 4, 7], | |
[2, 5, 8], | |
[0, 4, 8], | |
[2, 4, 6] |