5 posts in total


Posts tagged

module functions in Ruby

by Syed Aslam · 2 min read

In Ruby we can create module functions for named methods that may be called with the module as a receiver, and these functions also become available as instance methods to classes that mix in the module. There are multiple techniques to achieve this in Ruby, but the simplest and best known are Module#module_function and extend self.

magic comments in ruby

by Syed Aslam · 2 min read

Ruby supports magic comments (interpreter instructions) at the top of the source file, mostly known for setting a source files' Encoding. But there is more you can do.

Keeping array elements uniq in Ruby

by Syed Aslam · 1 min read

With uniq method you can remove duplicates from an array, however using the bitwise | operator we can avoid adding duplicate items in the first place.

Working with Files in Ruby

by Syed Aslam · 10 min read

The built-in class File provides the facilities for manipulating files in Ruby. Let us explore the basic file operations, including opening, reading, writing along with querying file objects to get information about the file itself.

Loading data from multiple files in Ruby using Hash

by Syed Aslam · 2 min read

There comes a time when you need to load data from multiple sources to futher processing in your application. Let's see how we can do this with ease in this post and load data from multiple files in Ruby using Hash.