Tidy introduction to Ruby
- Let's do this thing!
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.
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.
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 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…
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.
Short tip today, checking if a class is a subclass of another object.
A regular a link can only submit via get. To delete a resource you would usually submit a request via delete.
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.
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.
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.