Posts Tagged ruby

Enumerable grep method in Ruby

There is some methods that are not very known among ruby developpers. One of them is Enumerable#grep method. I would like to share one of the use case I have to face with, and how I implement grep. Purpose, I have a Hash representing a simple network I’d like to select all the people related [...]

, , , , , , , , , , , ,

No Comments

Email validation in Ruby On Rails 3 or Active model without regexp

In Rails 3.0, you can use custom validator in your active_record model. So I wanted to manage email validations without regexp matching like others do. I find a new way to make this work thanks to ruby mail gem, a dependency of Rails 3.0 class User < ActiveRecord::Base validates :email, :presence => true, :email => [...]

, , , , , , , , , , , , , , , , , ,

2 Comments

How to translate your column fields and values with gettext in ruby on rails

I am proud to have published my first useful ruby gem. It is called gettext_column_mapping, you can check out the code in my github repository. I already released it as a gem through gemcutter/rubygems It is based upon Masao Mutoh (gettext and gettext_active_record) and Michael Grosser (fast_gettext and gettext_i18n_rails) works. Thanks to them History In [...]

, , , , , , , , , , ,

No Comments

Bundler default Gemfile and custom Gemfile, example of wirble

Hi all, A simple trick I want to share with you if you are using Bundler (or rails 3) It matters if you want to install wirble gem in your workstation but not in your server Sometimes, you want to include some gem that are not mandatory for your application to run but you want [...]

, , , , , ,

No Comments

gettext 2.0.4 and rails 2.3.4

Rails 2.3.4 broke gettext_activerecord 2.0.4 Well I did not test other gems of the mutoh gettext set of libraries but here is the gulty code that breaks rails. Since Activerecord::Errors changed its implementation a bit, an error like this is raised : NoMethodError: undefined method `gsub’ for #<ActiveRecord::Error:0×00000002919738> from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:165:in `localize_error_message’ from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:112:in `block (2 [...]

, , , , , , , , , , ,

1 Comment

Ordered Hash by keys

Recently, I have to implement my own Hash sorting method. Not really with Hash but with ActiveSupport::OrderedHash I don’t like the way ActiveSupport::OrderedHash behaves with sorting functionality. It just behaves like a simple Hash I would like that sort return an ActiveSupport::OrderedHash not an Arrray!!! Why is it called OrderedHash in this case ? I [...]

, , , , , , , ,

No Comments

Inspectable accessors

Hey, it’s been a while I posted here. So what’s the purpose ? I commonly use script/console to debug my rails applications. Today I wanted to see the values of my custom attributes model without typing model.custom_attribute. So I took a look at ActiveRecord::Base#inspect method. and the default inspect method shows me database fields. Well, [...]

, , , , , , , ,

No Comments

Blocks are Proc : Les procédures Proc et les blocks en ruby.

( For non-french readers : I am not giving up writing in english … Read the next post! ) Si vous venez d’un autre langage, le terme procédure (associé au terme fonction) doit vous dire quelque chose. Vaguement …. Allez quelques connaissances (méconnaissances) tirées de ma mémoire pour poser les bases. Par exemple, en PHP [...]

, , , , , ,

No Comments

Class : to_s or not to_s ? That is the name !

Many rubyist use the method Class#to_s instead of Class#name My purpose (shared by some programmers) is that to_s is just a String representation of the Class not its name!! Imagine you want to store an ordered list of inherited subclasses as a String so you can retrieve the inheritance order of each subclass. class Parent [...]

, , , ,

2 Comments