At a recent Upstate Ruby meeting I had the opportunity to share a really cool editor I’ve been learning called Spacemacs (technically an Emacs starter kit). Here’s my screen recording including audio of the talk:
Spacemacs organizes key bindings under the space bar in a mnemonic form (p for…
So this is cool. Elixir allows you to define a simple test module like so:
defmodule DocTest do
use ExUnit.Case, async: true
Which is cool and does things! But what exactly does it do? It runs code examples in documentation comments.(If …
March has been both an exciting and crazy month. Let’s review what happened and what’s been going on.
Today I spent a good bit of time working on an algorithm to generate a primary navigation from an ordered list of pages using awesome_nested_set. This should be easy, right? Let’s try this out a few different ways.
Here’s the quick and dirty way to create an ordered hash from…
Today’s bits follow a random set of notes about the language syntax and me geeking out about a functional language and how it’s different from OO. In other words, you’ve probably read this before. Programming Elixir 1.2, here we go!
Lists are not arrays. Lists are not arrays. Lists are…
Elixir 1.2 has been released and so has a beta version of Dave Thomas’ book Programming Elixir. I’m taking the opportunity to read a new book and play with a new language all at once. Functional programming? I’m here for you!
Anyway, these are my notes from reading the book…
While reading an article today about what functional programming is, a comment rang true to me about the side-effects that might occur when a function calls a global element, such as a queue:
Can we test this code? Not in isolation. Unlike a circuit board, we can’t just plug into…
A random collection of logic to remember:
Logic: Ruby likes to return a value with the result of a boolean test, such as && or ||. This value varies depending on the operation:
Lastly an after_find and after_initialize callback is triggered for each object that is found and instantiated by a finder, with after_initialize being triggered after new objects are instantiated as well. http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
I found myself in the position today of needing a method run when a temporary model was instantiated but not saved. In other words, the code should happen in a typical class init function. I suppose this is one of the few areas where monkey-patching Ruby functions isn’t highly appreciated, but hey, I’m good with a callback.
In my testing, after_initialize is not a place to store code that should run every time a model is saved. For instance, if a model is instantiated, updated, and saved, the after_initialize will only occur on instantiation. Duh.
Here’s the gist of things: