Free course
Tidy introduction to Ruby
No Fluff
- Let's do this thing!
Ruby
I first encountered Ruby back when Rails first came out in 2005. Prior to that I had been doing most of my work in PHP, and like a lot of people, I was utterly blown away by how easy it was to get something going.
Later I went on to build StreetBank.com, a social enterprise that did quite well for a few years back before Facebook Marketplace was a thing. We aimed to put neighbours in touch with each other to share things, skills and friendship.
The Ruby Course
I originally built the Ruby course back in 2015 for a client called Deaf Alerter, who make fire alarms for deaf people, then later went on to deliver it to several dozen larger clients internationally. The material is available here, you're welcome to make any use of it you wish.
Writings
-
Using alias_method to preserve compatibility
The alias_method method allows us to alias call a method by a different name. If we change our API, we can still allow access using the old methods. This can save us a heavy refactoring job.
-
Shuffling up method params with parallel assignation
This little rockstar will make a whole RESTful form for you containing just one button, so you can make put, post and delete requests without relying on JavaScript. In this section, we’re going to look at how parallel assignation gives us two clean and simple ways to call the helper.
-
Using is_a? to vet method params
In Today’s Rails we’re inside the button_to helper once again. You may remember that this helper will make a whole RESTful form for you containing just one button.
-
Include vs. Extend
Include and Extend allow us to take methods from a module and add them to an object. They work slightly differently from each other though. Let’s take a look…
-
Delegating methods using extend
A change from Rails today, we’re dipping into Sinatra to look at how we can use extend to implement a Delegator. A delegator is an object which delegates responsibility to another object. Sinatra uses it to delegate methods called on the global scope to another object which can handle them.
-
Checking if an object is a subclass
Short tip today, checking if a class is a subclass of another object.
-
Today's Rails is the button_to helper
This little rockstar will make a whole RESTful form for you containing just one button, so you can make put, post and delete requests without relying on JavaScript.
A regular a link can only submit via get. To delete a resource you would usually submit a request via delete.
You can submit a delete request in two ways, either via JavaScript, or as a form submission. You don’t want an errant search engine spider hitting all your URLs and deleting all your data, so hiding delete links in this way is a good idea, since spiders generally won’t parse JavaScript or submit forms.
-
Using Object#blank? to check for whitespace
The blank? method is defined on object, and is not Rails specific. An object is blank if it is false, empty or a whitespace string.
-
Using dup to dry up bang methods. Bang bang!
Hello, and today we’re going to take a dip into Active Support to look at how we can use Object#dup to dry up bang methods. As you probably know, most methods are non destructive, but a bang method modifies an object in place. Here’s a non-destructive method, it returns a modified copy of the object. The original object is not changed. This is what we want to do most of the time.
-
Using a Rails concern to dry up Paperclip Attachments
Rails concerns have come in for a bit of a kicking lately, service objects clearly being a better solution in many instances, but I think there are valid use cases.
Concerns address the bloated model problem that plagues older Rails instances, where more and more methods are added to your fat models until they become huge and unwieldy. This slows your development as you now need to spend longer reading through code in order to get work done.