RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  
 

apeiros — 5 posts

http://apeiros.me

I very much dislike the all too common pattern
module Foo
def self.included(by)
by.extend ClassMethods
end
end

That's why I created the inherit gem. It's minimal (15 LoC relevant code).
Please check it out! Feedback is welcome!
The "sorting" gem provides utilities to make sorting with ruby easier.

Installation
gem install sorting

Usage
require 'sorting/convenience'
people.sort_by { |p| [desc(p.first_name), asc(p.age, :nils_last), asc { p.expensive }] }`


As you can see, it allows you to use sort_by to sort by ascending and descending values mixed, deal with potential nils, and performance optimization for expensive sort-values.
You can find more examples on the github page.

Future
I intend to add natural sorting (for which I already wrote plenty of code, the question is more how to fit it in best API-wise).

Feedback is very welcome!
fork gem released  rubygems.org
I released the fork gem, which provides a simple and object oriented interface to forking of your process.
The API provides ways to get the return value of a fork, get exceptions raised and send objects between the parent and a fork.
The project is - of course - found on github, and the documentation is available online.
I released the directory_template gem, which allows you to generate directory structures from a template, optionally processing paths
(variables in the path) and contents (e.g., render ERB templates).
You can write and use your own processors too (for both, path and content manipulation).
This is useful if you want to template e.g. Projects, or want to build something akin to rails' generators.
The project is - of course - found on github, and the documentation is available online.
Due to a series of questions on how to dynamically define local variables (which is an anti-pattern, mind you, you almost certainly should use a Hash instead), I went ahead and implemented Kernel#extract and Kernel#compact.
Ruby being OO, those pseudo-functions would probably be better implemented as methods (e.g. Binding#extract), but that's left as an exercise for the reader ;-)