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' | |
| module JSONable | |
| def to_json(*options) | |
| as_json(*options).to_json(*options) | |
| end | |
| end | |
| class Tag | |
| attr_reader :title |
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 SlackLogger | |
| def initialize(message) | |
| @message = message | |
| end | |
| def sending | |
| puts 'we sending message to Slack' | |
| end | |
| end | |
| class EmailLogger | |
| def initialize(message) |
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
| # some classes | |
| class SlackLogger | |
| def initialize(message) | |
| @message = message | |
| end | |
| def sending | |
| puts 'we are sending message to Slack' | |
| end | |
| end | |
| class EmailLogger |
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 Database | |
| @@instance = Database.new | |
| def self.instance | |
| return @@instance | |
| end | |
| private_class_method :new | |
| 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 Robot | |
| attr_reader :model_name, :id, :release_date | |
| def initialize(model_name:, id:, release_date:) | |
| @model_name = model_name | |
| @id = id | |
| @release_date = release_date | |
| end | |
| end | |
| class RobotFirstDecorator < SimpleDelegator |
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
| module SpamFilter | |
| def self.is_spam?(msg) | |
| # magic code is here | |
| end | |
| end | |
| # == Schema Information | |
| # | |
| # Table name: comments | |
| # |
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
| module TagCreator | |
| def self.render(tag_object) | |
| return '' if tag_object.nil? | |
| return tag_object if tag_object.is_a?(::String) or tag_object.is_a?(::Integer) | |
| str = "<#{tag_object.tag_name}>" | |
| str += TagCreator.render(tag_object.content) | |
| str += "</#{tag_object.tag_name}>" | |
| str | |
| 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
| require 'singleton' | |
| class Employee | |
| attr_accessor :name, :number, :address | |
| def initialize(args = {}) | |
| @name = args[:name] | |
| @number = args[:number] | |
| @address = args[:address] | |
| 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 AbstractLeaf | |
| def initialize; end | |
| def size | |
| raise 'Called abstract method: size' | |
| end | |
| end | |
| class AbstractComposite | |
| attr_reader :subgroup | |
| def initialize(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
| module Subject | |
| def initialize | |
| @observers = [] | |
| end | |
| def add_observer(event_type, observer) | |
| @observers << { event_type: event_type, observer: observer } | |
| end | |
| def delete_observer(event_type, observer) |