This file contains hidden or 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
| # 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 |
This file contains hidden or 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 "json" | |
| puts "Hash merging demo" | |
| json_hash = <<-EOS | |
| { | |
| "manifest":["manifest1"], | |
| "current": "string", | |
| "coverage": { | |
| "key": [1,2,null,null,1], |
This file contains hidden or 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
| def new_exception(exception_name) | |
| klass = Class.new Exception | |
| Object.const_set exception_name.to_s, klass | |
| end | |
| new_exception "CannotFindPants" | |
| new_exception :FlobbetsAreFlumoxed | |
This file contains hidden or 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
| def create_class(class_name, superclass, &block) | |
| klass = Class.new superclass, &block | |
| Object.const_set class_name.to_s, klass | |
| end |