Skip to content

Instantly share code, notes, and snippets.

View shadchnev's full-sized avatar

Evgeny Shadchnev shadchnev

  • Makers Academy
  • London
View GitHub Profile
class User
MIN_RANK = -8
MAX_RANK = 8
RANKS = (MIN_RANK..MAX_RANK).to_a - [0]
REWARDS = {-2 => 0, -1 => 1, 0 => 3}
attr_reader :rank, :progress
def initialize
class Cell
attr_accessor :value
def empty?
@value.nil?
end
def possible_values(neighbours)
(1..9).to_a - neighbours
@shadchnev
shadchnev / array_spec.rb
Created August 28, 2013 10:23
Basic array test
describe Array do
it 'should know its size' do
array = [1,2,3,4]
array.size.should eq(4)
end
it 'should be created with default value' do
array = Array.new(3) { "fizz" }
@shadchnev
shadchnev / polite_mailer.rb
Created June 14, 2013 10:14
Polite mailer
class PoliteMailer
def send(to)
message = %Q[message for #{to}
Hello,
How are you today?
I just had a great idea:
#{yield}
Hope to hear from you soon
Best regards
@shadchnev
shadchnev / bitcoin.rb
Created June 14, 2013 09:46
Ruby blocks and observer pattern example
class Bitcoin
def initialize
@observers = Hash.new
# {:coin_mined => [handler_block1, handler_block2]}
end
def mine!
100.times do |i|
trigger(:coin_mined, i) if i % 13 == 0
@shadchnev
shadchnev / tic_tac_toe_test.rb
Last active December 18, 2015 04:49
Very simple Tic Tac Toe game test
require 'minitest/autorun'
require '../lib/tic_tac_toe'
class TicTacToeTest < Minitest::Test
# the board is represented as a string of rows, e.g.
# X | | X
# ---------
# 0 | 0 | X
# ---------
class AirportTest
def setup
@airport = Airport.new
end
def test_plane_can_land
end
# A plane currently in the airport can be requested to take off.