Sarah Mitchell

33 code snips · on codesnips 5 months

Senior Ruby Developer with 10+ years of experience crafting elegant, performant Rails applications. Deep expertise in Ruby metaprogramming, Rails internals, and building...

ruby
# Gemfile
gem 'dry-types'
gem 'dry-struct'

require 'dry-types'
require 'dry-struct'

Dry-rb gems for functional programming patterns

ruby dry-rb functional-programming
by Sarah Mitchell 2 tabs
ruby
# Define refinements in a module
module StringExtensions
  refine String do
    def titleize
      split.map(&:capitalize).join(' ')
    end

Ruby refinements for scoped monkey patching

ruby refinements monkey-patching
by Sarah Mitchell 2 tabs
ruby
# Basic Ractor usage
ractor = Ractor.new do
  # This runs in parallel, isolated from main thread
  result = heavy_computation
  result
end

Concurrent Ruby with Ractors and Async

ruby concurrency parallelism
by Sarah Mitchell 2 tabs
ruby
# app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
  default from: 'noreply@example.com'

  def welcome_email(user)
    @user = user

ActionMailer advanced patterns for transactional emails

ruby rails action-mailer
by Sarah Mitchell 2 tabs
ruby
# Gemfile
gem 'view_component'

# app/components/button_component.rb
class ButtonComponent < ViewComponent::Base
  VARIANTS = %w[primary secondary danger].freeze

ViewComponent for reusable, testable view components

ruby rails view-component
by Sarah Mitchell 2 tabs
javascript
// app/javascript/controllers/dropdown_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["menu"]

Stimulus for sprinkles of JavaScript interactivity

ruby rails stimulus
by Sarah Mitchell 3 tabs
ruby
# Generate engine
# rails plugin new billing --mountable

# lib/billing/engine.rb
module Billing
  class Engine < ::Rails::Engine

Rails engines for modular applications

ruby rails engines
by Sarah Mitchell 2 tabs
ruby
# Gemfile
gem 'graphql'

# Installation
# rails generate graphql:install

GraphQL APIs with graphql-ruby gem

ruby rails graphql
by Sarah Mitchell 3 tabs
ruby
class Money
  include Comparable

  attr_reader :amount, :currency

  def initialize(amount, currency = 'USD')

Value objects for domain modeling

ruby value-objects domain-driven-design
by Sarah Mitchell 2 tabs
ruby
# Installation
# rails active_storage:install
# rails db:migrate

# config/storage.yml
local:

ActiveStorage for file uploads and attachments

ruby rails active-storage
by Sarah Mitchell 2 tabs
ruby
# Gemfile
gem 'draper'

# app/decorators/user_decorator.rb
class UserDecorator < Draper::Decorator
  delegate_all

Decorator pattern with Draper for view logic

ruby rails draper
by Sarah Mitchell 2 tabs
ruby
# Gemfile
group :development do
  gem 'rack-mini-profiler'
  gem 'memory_profiler'
  gem 'stackprof'  # For flamegraphs
  gem 'bullet'     # N+1 detection

Performance profiling with rack-mini-profiler and tools

ruby rails performance
by Sarah Mitchell 2 tabs