Last Updated: February 25, 2016
·
1.343K
· thomas el p

Ruby Core Extends

There are two usefull gems who extends Hash and Array classes. No override so it won't change default rauby functions.

Works in ruby 1.8 - 1.9 and rails 2.3 - 3

Gem : hash_extend
see on github : Link
see on rubygem : Link

Gem : array_extend
see on github : Link
see on rubygem : Link

Edit : These gems are similar - for the idea - to Rails's ActiveSupport. Through, one made me realize that I made some duplicates regarding of ActiveSupport core extends, so there is a few deprecated methods.

5 Responses
Add your response

What's the benefit of using this instead of ActiveSupport core extensions?

over 1 year ago ·

This is not an alternative to ActiveSupport core extensions. To anwser your question : none.

The idea behind theses gems is the same as the idea of ActiveSupport core extentions : provide more methods because we need them, and ruby don't provide them now.

For example, the 'stealthdelete' function. There is nothing like that in ruby, neither in ActiveSupport core extentions. Nevertheless I want to be able to delete a key from my hash and returning the hash, not the value.
To do something like (rails) : Membre.new :attributes=>params.stealth
delete :action, :controller

I used to have a core_ext folder in my /lib (rails). I transform it into gem to use it through all my projects, and share it.

over 1 year ago ·

I think you're reinventing the wheel here. You say that this is not the alternative to ActiveSupport, but they both share the same idea.
I've checked out the #stealth_delete source. There's the method in AS that provides the same functionality: http://api.rubyonrails.org/classes/Hash.html#method-i-except

I'm opinionated that you'll find a replacement (ruby or rails) for almost any functionality your gem supports. If not, you should consider opening up a pull request on AS and adding your desired functionality. This way, your code gets revived by Rails core team and you'll get a great feedback on your code quality.

Why opening up a pull request on AS instead of building your own gems?
Because rails devs are familiar with AS and I'm sure anyone would rather see the names of familiar methods, than from the new gem.

Do you share my opinion? :)

over 1 year ago ·

Yes you'r right. I didn't knew about the #except method and it surely is better to use this than my #stealth_delete.

I may be blinded to these functionalities rails provindes because I use rails 2.3 at work.

You'r also right about opening pull request on AS. I never considered this option.

Well, I will check in deep the features AS provide before doing my own.

over 1 year ago ·

<3

Sharing opinions to give you some insight!

over 1 year ago ·