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 'socket' | |
| module EventEmitter | |
| def _callbacks | |
| @_callbacks ||= Hash.new { |h, k| h[k] = [] } | |
| end | |
| def on(type, &blk) | |
| _callbacks[type] << blk | |
| self |
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 generate_options(condition) | |
| case condition.to_s | |
| when "invalid_reg_exp" | |
| {:response_msg => "Validation Failed(NON-SMTP)",:status=>"FAILED",:email_status=>"INVALID"} | |
| when "free_domain" | |
| {:response_msg => "Free Domain",:status=>"FAILED",:email_status=>"NEUTRAL"} | |
| when "server_failure" | |
| {:response_msg => "Mail Server Not Connected",:status=>"FAILED",:email_status=>"NEUTRAL"} | |
| when "valid" | |
| {:response_msg => condition.response,:status=>"VERIFIED",:email_status=>"VALID"} |
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
| class FormattedTable | |
| def initialize(table) | |
| @table = table | |
| end | |
| def to_s | |
| @table.map { |row| row.join(" | ") }.join("\n") | |
| end | |
| end |
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
| class EventHandler | |
| def initialize | |
| @callbacks = Hash.new { |h,k| h[k] = [] } | |
| end | |
| def on(event, callback) | |
| @callbacks[event] << callback | |
| end | |
| def trigger(event, *args) |
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
| class EventHandler | |
| def initialize | |
| @callbacks = Hash.new { |h,k| h[k] = [] } | |
| end | |
| def on(event, callback) | |
| @callbacks[event] << callback | |
| end | |
| def trigger(event, *args) |
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
| class EventHandler | |
| def initialize | |
| @callbacks = Hash.new { |h,k| h[k] = [] } | |
| end | |
| def on(event, callback) | |
| @callbacks[event] << callback | |
| end | |
| def trigger(event, *args) |
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 "bigdecimal" | |
| class Node | |
| def initialize(name) | |
| @name = name | |
| @children = [] | |
| end | |
| attr_reader :name |
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
| class A { | |
| private B b; | |
| private C c; | |
| private D d; | |
| private E e; | |
| public A () { | |
| b = new B (); | |
| c = new C (); | |
| d = new D (); |
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
| ### LESSON 2: Refactoring is not redesign | |
| https://github.com/mendicant/mendicantuniversity.org/wiki/TDD-study-session-%282012-May-03%29 | |
| code that needs redesign is not necessarily messy, just no longer correct | |
| testing eases refactoring but has a complicated effect on redesign | |
| http://devblog.avdi.org/2012/06/25/every-day-in-every-way/ | |
| A refactoring is an atomic and safe change that can be described in a sentence |
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
| puts 'Hello, and welcome to seventh grade English.' | |
| puts 'My name is Mrs. Crabbage. And your name is...?' | |
| name = gets.chomp | |
| # instead of name = 'jana' or 'Jana' do this... | |
| if name == 'jana' || name == 'Jana' | |
| puts 'Oh, YOU again. Please take a seat.' | |
| end | |
| # we usually use || instead of or, because it works |