Skip to content

Instantly share code, notes, and snippets.

View mcgain's full-sized avatar

Richard McGain mcgain

View GitHub Profile
@mcgain
mcgain / tennis.rb
Last active November 5, 2020 06:09
# This is not my code, I took it from https://blog.arkency.com/10-lessons-learnt-from-the-ruby-refactoring-kata-tennis-game/.
# I'd advise not clicking through to that link since it shows some refactoring.
require 'minitest/autorun'
class TennisGame1
def initialize(player1Name, player2Name)
@player1Name = player1Name
@player2Name = player2Name
require "json"
puts "Hash merging demo"
json_hash = <<-EOS
{
"manifest":["manifest1"],
"current": "string",
"coverage": {
"key": [1,2,null,null,1],
@mcgain
mcgain / gist:3694817
Created September 10, 2012 23:37
terse exception creation
def new_exception(exception_name)
klass = Class.new Exception
Object.const_set exception_name.to_s, klass
end
new_exception "CannotFindPants"
new_exception :FlobbetsAreFlumoxed
@mcgain
mcgain / gist:3694734
Created September 10, 2012 23:22
Ruby create class method
def create_class(class_name, superclass, &block)
klass = Class.new superclass, &block
Object.const_set class_name.to_s, klass
end