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 NanoCase | |
class Result | |
UNDEFINED = :undefined | |
attr_reader :type, :data | |
def initialize(type, data) | |
@type = type | |
@data = data | |
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 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'benchmark-ips', '~> 2.11' | |
end | |
class Calc | |
def initialize(a, b) |
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 FactoryCollectionFilter | |
def initialize(config) | |
@config = config || {} | |
end | |
def call(filters: {}, data: []) | |
return data if filters.empty? | |
filters.reduce(data) do |filtered, (filter, value)| | |
filter_fn = @config[filter] |
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
#################################### | |
# Pilares da Orientação a Objetos: # | |
#################################### | |
# 👍 Abstração. | > | |
# 👍 Encapsulamento | > > Composição 🙌 | |
# 👍 Polimorfismo | > | |
# 👎 Herança |
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 AssemblyLine | |
CARS_PRODUCED_PER_HOUR = 221.0 | |
def self.calculate_cars_per_hour(speed) | |
speed * CARS_PRODUCED_PER_HOUR | |
end | |
def self.calculate_success_rate(speed) | |
case speed | |
when 1..4 then 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
class Mecha | |
private attr_accessor(:states_map, :callbacks, :transitions, :current_state) | |
public :transitions, :current_state | |
def initialize(initial_state:, transitions:) | |
self.states_map = transitions.parameters.select { |(type, _)| type == :keyreq }.to_h { [_2, _2] } | |
self.callbacks = Hash.new { |hash, key| hash[key] = [] } | |
self.transitions = transitions.call(**states_map).transform_values(&:freeze).freeze |
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 Susurro | |
def subscribe(handler) | |
subscribers << {name: nil, handler: handler} | |
self | |
end | |
def on(event_name, &handler) | |
subscribers << {name: event_name, handler: handler} |
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 'uri' | |
require 'json' | |
require 'net/http' | |
# https://dog.ceo/dog-api/ | |
class DogCeoAPI | |
class FakeStrategy | |
def get_random | |
{ | |
"message" => "https://images.dog.ceo/breeds/terrier-welsh/lucy.jpg", |
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 Kind | |
module Interface | |
module State | |
extend self | |
@current = :enabled | |
def disable! | |
@current = :disabled | |
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 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'rspec', '~> 3.10' | |
gem 'activesupport', require: 'active_support/all' | |
end | |
module Calc |
NewerOlder