Tag Archive: best practice

Jan
12

HTTPClient and SSL verify certificate

If you as us in my company use self signed certificate and ran into an OpenSSL::SSL::SSLError when using httpclient gem. Here is how to bypass ssl certificate verification : The issue : require ‘rubygems’ require ‘httpclient’   client = HTTPClient.new url = "https://www.server1.com" client.get(url) at depth 1 – 19: self signed certificate in certificate chain …

Continue reading »

Nov
17

ActiveRecord like searching object in Rails form helpers

Ruby is a wonderful language. And Rails is a wonderful framework. Why ? Because of Duck typing !!! Example : You build a database application for a book store Books are classified by : Genre Author Country On a search page, you can search with a title text field, author select box, genre checkboxes. So …

Continue reading »

Aug
19

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 …

Continue reading »

Oct
02

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 …

Continue reading »

Jul
10

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 …

Continue reading »