Skip to content

Instantly share code, notes, and snippets.

View baweaver's full-sized avatar
📝
Documenting things

Brandon Weaver baweaver

📝
Documenting things
View GitHub Profile
@baweaver
baweaver / ruby_books.md
Last active March 12, 2024 06:51
A list of books for learning and expanding on your Ruby knowledge.

Ruby Book List

Learning Ruby

You're taking your first steps into Ruby

A good introduction to programming in general. Easy on newer programmers.

@baweaver
baweaver / ruby_ast_translate.rb
Created February 28, 2024 09:10
Ruby AST translator hack - Needs a lot of work later, but hey, proof of concept
require 'rubocop'
# Target - What I want to get to
# class ShorthandProcCallMacro2 < Rule
# matches "$receiver.$method_call { |$arg| $arg.$arg_name }"
# replaces "$receiver.$method_call(&:$arg_name)"
# end
class Literal
def initialize(s)
@baweaver
baweaver / evolution_of_ruby_programmer.md
Last active February 22, 2024 21:27
Very much work in progress, will amend this as I have time. Feel free to comment ideas.

Refactoring with ASTs and Pattern Matching

Pattern matching in Ruby is not a well understood or frequently used feature, but when paired with ASTs it becomes an incredibly powerful tool for refactoring and code transformations.

Details

This talk is a deep dive into ASTs and RuboCop as refactoring and upgrade tools. With the advent of language servers this will become a very critical topic to have knowledge in to effectively work with manipulating Ruby code programatically.

Intended Audience

@baweaver
baweaver / row_me_lemur_friends.txt
Created November 21, 2023 08:47
Row Me Lemur Friends - Variant of "Row Me Bully Boys"
Based on: https://www.youtube.com/watch?v=wf-4vexIOqc
I'll code you some Ruby, it's Ruby with C
Code me Lemur friends code
Oh I'll FFIddle some C if you'll debug it with me
And it's code me Lemur friends code
And it's code me Lemur friends
We're in a hurry then
We got a long sprint to go

Agenda:

  • Introductions - Coaches (5m)
    • Share names and pronouns
    • Brief history on what they do and how they work with Ruby
    • A tip or two on writing an awesome CFP
  • Introductions - Prospective Speakers (15m)
    • Share names and pronouns
    • Brief history on what they do and how they work with Ruby
  • Where are they in the process of writing their CFP (ideation, first draft, proofreading)
@baweaver
baweaver / block_transform_ast.rb
Last active August 3, 2023 22:53
Pattern matching applied to ASTs, defining the transformation between shorthand and standard block format.
require "rubocop"
# Useful for debugging and seeing how the nodes deconstruct
def deep_deconstruct(node)
return node unless node.respond_to?(:deconstruct)
node.deconstruct.map { deep_deconstruct(_1) }
end
def block_to_shorthand?(a, b)
def roman_numeral(n) = case n
in 1000..3000 then 'M' + roman_numeral(n - 1000)
in 900..999 then 'CM' + roman_numeral(n - 900)
in 500..899 then 'D' + roman_numeral(n - 500)
in 400..499 then 'CD' + roman_numeral(n - 400)
in 100..399 then 'C' + roman_numeral(n - 100)
in 90..99 then 'XC' + roman_numeral(n - 90)
in 50..89 then 'L' + roman_numeral(n - 50)
in 40..49 then 'XL' + roman_numeral(n - 40)
in 10..39 then 'X' + roman_numeral(n - 10)
@baweaver
baweaver / DependencyInjectionInRuby.md
Last active March 7, 2023 04:43 — forked from blairanderson/DependencyInjectionInRuby.md
Dependency Injection in Ruby. Originally from Jim Weirich’s blog which does not exist except for googles cache. (I wanted headers, so fork it is)

Dependency Injection in Ruby 07 Oct 04

Introduction

At the 2004 Ruby Conference, Jamis Buck had the unenviable task to explain Dependency Injection to a bunch of Ruby developers. First of all, Dependency Injection (DI) and Inversion of Control (IoC) is hard to explain, the benefits are subtle and the dynamic nature of Ruby make those benefits even more marginal. Furthermore examples using DI/IoC are either too simple (and don’t convey the usefulness) or too complex (and difficult to explain in the space of an article or presentation). I once attempted to explain DI/IoC to a room of Java programmers (see onestepback.org/articles/dependencyinjection/), so I can’t pass up trying to explain it to Ruby developers.

Thanks goes to Jamis Buck (the author of the Copland DI/IoC framework) who took the time to review this article and provide feedback.

What is Dependency Injection?

class Cond
IDENTITY = -> v { v }
def initialize(if_cond: IDENTITY, then_branch: IDENTITY, else_branch: IDENTITY)
@if_cond = if_cond
@then_branch = then_branch
@else_branch = else_branch
end
def call(v)