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
#!/usr/bin/env ruby | |
# pingpongninja_expected_results -- simulate a series of games on pingpongninja | |
# | |
# algorithm extracted from | |
# https://github.com/jdennes/pingpongapp/blob/master/pingpong/rankings.py | |
def new_ranks(rank1, rank2, points1, points2) | |
decay_factor = 10 | |
game_ranking_points = (rank1 + rank2) / 2 | |
ranking_change1 = game_ranking_points + (points1 - points2) * 100 / [points1, points2].max | |
ranking_change2 = game_ranking_points + (points2 - points1) * 100 / [points1, points2].max |
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 Foo | |
class << self | |
def hello | |
"hello" | |
end | |
end | |
end | |
def singleton &block | |
singleton_class.class_eval &block |
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 Evaluator | |
def evaluate &block | |
instance_eval &block | |
end | |
def upcase bar | |
bar.upcase | |
end | |
end |
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
module IPoint | |
attr_accessor :x, :y | |
end | |
module IReadonlyPoint | |
attr_reader :x, :y | |
end | |
module IReadonlyLine | |
attr_reader :source, :destination |
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
time_range = Time.now .. Time.now | |
number_range = 1.0 .. 10.0 | |
p time_range.cover? Time.now | |
p number_range.cover? 5.0 | |
begin | |
time_range.to_a | |
rescue | |
puts "time_range is unenumerable" |
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 'test_helper' | |
class MiniTestDoesntWorkWithUnenumerableRangesTest < ActiveSupport::TestCase | |
test ":(" do | |
period = Time.current - 1.week .. Time.current | |
mock = MiniTest::Mock.new | |
mock.expect :foo, true, [period] | |
mock.foo period |
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 "i18n/backend/fallbacks" | |
I18n::Backend::Simple.send :include, I18n::Backend::Fallbacks | |
I18n.backend.store_translations :en, test: { | |
no_translations: { | |
specific: "en specific", | |
generic: "en generic", | |
}, | |
only_generic_translations: { |
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
source 'https://rubygems.org' | |
gem 'fruity', '~> 0.2.0' | |
gem 'rubyzip', '1.1.0' | |
gem 'zippo', '0.2.0' |
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 Collaborator | |
# not implemented yet because TDD! | |
end | |
class ThingThatDoesThings | |
def initialize name | |
@name = name | |
end | |
def do_thing with |
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 'unicode_utils' | |
baffle = 'baffle' | |
puts baffle # => baffle | |
puts baffle.upcase # => BAfflE | |
puts UnicodeUtils.upcase(baffle) # => BAFFLE | |
noel = 'noël' |