You're taking your first steps into Ruby
A good introduction to programming in general. Easy on newer programmers.
You're taking your first steps into Ruby
A good introduction to programming in general. Easy on newer programmers.
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) |
A fun joke based on Evolution of a Haskell Programmer.
require "minitest/autorun"
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.
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.
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:
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) |
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.
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) |