How to: YourGem.configure

Really cool gems, like Carrierwave for example, have this neat feature of configuring the gem in runtime. It allows you to easily configure how the gem will behave in your app. For example, you can add various authentication keys, how errors should be handled and what not. If you want to add this cool functionality in your gems, read on to find out more. Personally, I love to implement (and use) this way of configuring libraries in runtime.

RailsConf 2015 talks that you should watch

Recently Confreaks uploaded a ton of RailsConf 2015 talks on Youtube. Although I haven’t watched all of the talks, these are some of the ones that in my opinion are very worth watching. Keep in mind that this list will grow as I watch more talks over time. So, without further ado… So You Want to Start Refactoring? by @j3foley In this talk, Jillian Foley talks about refactoring. She shares some techniques about how to approach code that you haven’t written and how to easily refactor it.

How to write RSpec formatters from scratch

Recently I did an experiment with RSpec’s formatters. Turns out, the output that RSpec returns when you run your specs can be very customized for your own needs. Read on to learn how you can write custom RSpec formatters. Writing custom formatters RSpec allows customization of the output by creating your own Formatter class. Yep, it’s that easy. You just need to write one class and than require it into RSpec’s configuration to use it.

Pattern to pattern: Template Method & Strategy

Recently I wrote about the Template Method pattern and how it’s implemented in Ruby. In the comments, one of the readers commented that the Template Method pattern is in fact the Strategy pattern. After thinking hard about how I should answer the question, I thought about writing a post comparing the two patterns. So, here it is - my version of design patterns head to head. Let’s see what these two patterns have in common and what are their key differences.

Exploring new methods in Ruby 2.2.0

For those late to the Ruby 2.2.0 party like me, aside from the changes (and updates) the core team made under the hood for this version, they introduced couple of new methods to the _Enumerable_ module and to the Method, Float, File and String classes. Lets take a look at these methods and explore how we can use them in our everyday jobs. Just a heads up, make sure you use Ruby 2.

Using multiple sources in a Gemfile

Gemfiles require at least one gem source, in the form of the URL for a RubyGems server. Although it’s not recommended, it’s possible as of Bundler 1.7, to add multiple global source lines. Each of these sources has to be a valid Rubygems repository. When using multiple sources, bundler shows a warning message: Although, this warning can be disabled by running the bundle config disable_multisource true command, there’s a better approach to this.

Template Method Pattern in Ruby

When working as a software developer, knowledge of some design patterns is always welcomed. If you’ve never heard about design patterns, they are basically some general reusable patterns for common problems that developers run into. There’s a big list of these and knowing all of them is a bit hard. Well, hard might not be the right word, but it takes a lot of practice to master them all. Lets take a look at one of the (in my opinion) easier patterns - the Template Method Pattern and implement it in Ruby.

AngularJS Services Part 4: Value and Constant

So far we saw the magic of creating AngularJS services using Provider, Factory and Service. In this post, we will look at two more types of services - Value and Constant. Value The Value service is basically a service that returns a single value, like, string, object, number or an array. For instance: (function(){ angular.module('app', []) .value("Number", 24) .value("String", "Hey, how are you?") .value("Object", { prop1: 'prop1', prop2: 'prop2' }) .

AngularJS Services Part 3: Service

So, Service is basically the same as Factory, it just has one key difference. Service treats the function as a constructor, meaning, the service will call new on the function and return the resulting object as a service object. Oh, if you haven’t yet read about Factory, check out AngularJS Services Part 2: Factory. Using Service Declaring a Service is easy. Lets look at an example. 1 2 3 4 5 6 7 8 9 10 (function(){ angular.

AngularJS Services Part 2: Factory

If you don’t know the basics of AngularJS service, I recommend you read the other article I wrote on AngularJS Services Part 1: Provider. Provider v.s. Factory Factory is a thin wrapper on top of Provider. While Provider provides us the ability to configure the service provider before injection (creating the service object), Factory lacks that ability. Although it is short of this functionality, most of the Angular devs use factories because they are, in my opinion, the easiest to use and really cover all the general needs that one might need from a service.

AngularJS Services Part 1: Provider

I started using AngularJS couple of months ago, when we got a new client that wanted us to help with building an app written in Angular. After couple of months of using it, I found myself struggling with uber-phat controllers and I started thinking of solutions about extracting knowledge out of the controller into separate entities. Also, having the ability to easily inject those entities back into the controller is a must.

SOLID Principles in Ruby

Regardless of your knowledge level, as a programmer you love to write awesome code. It’s what we do. We like it and we do it every single day. But, we all know that writing awesome code is not easy at all. So, how can we improve the code we produce every day? An awareness (or a reminder!) of SOLID principles is beneficial here. SOLID is a group of five principles that when applied correctly can help us produce better code.