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 SRPViolationError < StandardError | |
| def initialize(klass) | |
| @klass = klass | |
| end | |
| def message | |
| "Class #{@klass} surely does something AND detects SRP violation, right? Well, your class should do only one thing! :D" | |
| 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
| { | |
| "indices":{ | |
| "crowdcloud_production":{ | |
| "index":{ | |
| "primary_size":"22.5gb", | |
| "primary_size_in_bytes":24211211120, | |
| "size":"22.5gb", | |
| "size_in_bytes":24211211120 | |
| }, | |
| "translog":{ |
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
| bus = On::Bus.new. | |
| subscribe(DonationReceipt). | |
| subscribe(NotifyAccountingSystem). | |
| subscribe(UpdatePublicStats). | |
| subscribe(LogInternalMetrics). | |
| subscribe(UpdateAnalyticsDashboard). | |
| subscribe(RealtimeViewerUpdate) |
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 DonationsController # < ActionController::Base | |
| def create | |
| donation_service.add_donation(current_user, params, bus.on( | |
| donation_created: ->(donation) { send_user_to_payment_gateway(donation) }, | |
| donation_invalid: ->(donation) { render donation.errors, status: :bad_request } | |
| )) | |
| end | |
| private | |
| def donation_service |
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
| # sandi | |
| module GildedRose | |
| DEFAULT_CLASS = Item | |
| SPECIALIZED_CLASSES = { | |
| 'normal' => Normal, | |
| 'Aged Brie' => Brie, | |
| 'Backstage passes to ...' => Backstage | |
| } | |
| def self.for(name, quality, days_remaining) |
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 link_to_notifiable(notifiable) | |
| notifiable.link_to_notifiable(self) | |
| end | |
| # concerns/notifiable_presenters.rb | |
| class Answer | |
| def link_to_notifiable(helper) | |
| helper.link_to_answer, question | |
| 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 InviteController < ApplicationController | |
| # The controller's responsibility is to build an object graph | |
| # that will do the hard work. | |
| def accept | |
| scenario = InvitationScenario.new | |
| scenario.accept_invite_token_for_user(current_user, params[:token], bus.when( | |
| inviting_succeeded: ->(user) { redirect_to invite.item, notice: "Welcome!" }, | |
| inviting_failed: ->(error) { redirect_to '/', alert: "Oopsy!" } | |
| )) |
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 'minitest/autorun' | |
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 'minitest/autorun' | |
| ARABIC_VALUES = { | |
| 'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000 | |
| } | |
| def from_roman(roman) | |
| chars = roman.chars << 'I' | |
| chars.each_cons(2).inject(0) do |sum, (c1, c2)| | |
| sum + (ARABIC_VALUES[c1] < ARABIC_VALUES[c2] ? -ARABIC_VALUES[c1] : ARABIC_VALUES[c1]) |
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 Number < Struct.new(:value) | |
| def print | |
| value | |
| end | |
| end | |
| class Binary < Struct.new(:left, :right) | |
| end | |
| class Plus < Binary |