Skip to content

Instantly share code, notes, and snippets.

Documenting things

Brandon Weaver baweaver

Documenting things
Block or report user

Report or block baweaver

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ast_source.rb
# 1 + 1'1 + 1').to_ast.source
=> "1 + 1"
# From s-expressions
ast = { s(:send, s(:int, 1), :+, s(:int, 1)) }.to_ast
=> s(:send, s(:int, 1), :+, s(:int, 1))
# Current
View hash_lvar.rb
# Original Code
hash = { something: 'fun' }
method_called(with, some, hash)
(lvasgn :hash
(sym :something)
View route_hash_args_ast.rb
(def :route
(arg :verb)
(arg :path)
(optarg :options
(blockarg :block))
(lvasgn :signature
View hanging_indentation.rb
# Bad - Hard to read
# Good - Eye doesn't flow far right then
baweaver / rubyconf_2019_raffle_winner.rb
Created Dec 17, 2019
My spectacularly convoluted selection criteria
View rubyconf_2019_raffle_winner.rb
names = %w(
@OtherChrisPine @DaveAronson @mellowfish @ktcarrel18 @yvonesre @molbrwn @_MylesHigh_ @DoodlingDev @nilsding @mae701
totally_random_results = "Lemur fun!"
View pattern_matching_cons.rb
Cons =, :tail)
case Cons[1, Cons[2]]
in Cons[head. tail] then [head, tail]
# => [1, #<struct Cons head=2, tail=nil>]
case Cons[1, Cons[2]]
in Cons[1, Cons[head, tail]] then [head, tail]
View pattern_match_hash_array.rb
case { it: { works: { on: 1, nested: 'hashes' }, cool: true } }
in it: { works: { on: Integer, nested: String }, cool: TrueClass }
# => true
case [{ that: { includes: [:this, :too] }}, { more: 'splats'}, {see?: true}]
in [{ that: { includes: Array } }, *]
baweaver /
Created Nov 24, 2019
Current WIP of pattern matching documentation. Still needs more work.

Pattern Matching

Pattern match statements are an extension of the case expression. They introduce a new keyword to case statements: in.

The in expression

in is used in place of when to use pattern matching behaviors. These two syntaxes cannot be mixed.

An in expression is different from when in that it allows one to match against data structures:

baweaver / symbol_ap.rb
Created Oct 19, 2019
Stealing some vague ideas from Applicatives in Haskell, probably wrongly but it amuses me so...
View symbol_ap.rb
class Symbol
def ap(*applied_args)
-> *block_args {
if applied_args.empty?
receiver, *new_args = block_args[0]
receiver.send(self, *new_args)
else*block_args, *applied_args)
baweaver / favorite_things_ruby_edition
Last active Sep 21, 2019
A Few of my Favorite Things translated to Ruby (WIP)
View favorite_things_ruby_edition
Ruby programming
And Gems pushed to GitHub
Cloud based deployments and CI / CD
Tests that will pass on the first try
These are a few of my favorite things
Just Rails new app name
and omakase thinking
convention o'er configuration
and sane default settings
You can’t perform that action at this time.