Skip to content

Instantly share code, notes, and snippets.

View alessandro-fazzi's full-sized avatar
🇺🇦

Alessandro Fazzi alessandro-fazzi

🇺🇦
View GitHub Profile
@alessandro-fazzi
alessandro-fazzi / ancillary_objects.ipynb
Created May 21, 2024 14:08
[Ruby] Ancillary objects and inheritance: an alternative take
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alessandro-fazzi
alessandro-fazzi / study_pattern_matching_custom_matchers.ipynb
Last active December 17, 2023 22:54
[Study] Custom matchers for pattern matching
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alessandro-fazzi
alessandro-fazzi / Gemfile
Last active July 13, 2023 20:06
[study] Ruby method overloading in 2023
# frozen_string_literal: true
source 'https://rubygems.org'
# gem "rails"
gem 'benchmark-ips'
gem 'rubocop'
gem 'stackprof'
gem 'stackprof-webnav'
@alessandro-fazzi
alessandro-fazzi / README.md
Last active July 3, 2023 11:52
Why I think an "open" decorator is mostly a bad idea

Why I think an "open" decorator is mostly a bad idea

First thing first: when I speak about open decorators I mostly refer to the delegate_all (anti)pattern introduced in many Rails applications by the widely used draper gem. With "open" adjective I refer to the fact that the decorator responds to all the messages as the underlying decorated object. This is like a transparent ill variation of the proxy pattern: if you need proxy pattern[^1] then you want to re-bound the interface, lowering required knowledge as much as you can, lowering responsibilities and lowering the maintenance of boundaries between objects and application layers as much as you are able to.

Draper is a (sort of) presenter

While the family of decoration patterns[^2] is large and with subtle differences between one member and another, I consider Draper's decorators as decorators for the view layer, thus we could speak more of a presenter[^3]. The readme of the gem itself says

@alessandro-fazzi
alessandro-fazzi / method_params_validation.rb
Last active June 23, 2023 10:30
[study] Method's parameters validation
module ValidatableMethods
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def validated(method_name, &block)
mod = Module.new
mod.define_method(method_name) do |*args, **kwargs|
begin
@alessandro-fazzi
alessandro-fazzi / .ruby-version
Last active December 12, 2022 22:12
[Study] An alternative approach managing LightService hooks
3.1.1
@alessandro-fazzi
alessandro-fazzi / main.rb
Created November 23, 2022 15:31
avo-qh/class_variants without the gem
ButtonClasses = Struct.new(:classes, :variants, :defaults, keyword_init: true) do |klass|
def render(**settings)
result = []
# Add the default classes if any provided
result << classes if classes
# Keep the applied variants so we can later apply the defaults
applied_options = []
# CLOSURES IN RUBY Paul Cantrell https://innig.net
# Email: username "paul", domain name "innig.net"
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself an unreasonable Ruby test by deleting all
# the comments, then trying to guess the output of the code!
#
# (Naive HR departments, please do not use that idea as a hiring quiz.)
@alessandro-fazzi
alessandro-fazzi / Gemfile
Created July 28, 2021 17:46
LightService Organizer with dependency injection
source 'https://rubygems.org'
gem 'light-service'
gem 'dry-auto_inject'
gem 'pry-byebug'
@alessandro-fazzi
alessandro-fazzi / cloudSettings
Last active July 25, 2019 09:18
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-07-25T09:18:20.382Z","extensionVersion":"v3.4.1"}