Parse Date string in Ruby

You could use the Date.strptime method provided in Ruby’s Standard Library: require ‘date’ string = “20120723” date = Date.strptime(string,”%Y%m%d”) Alternately, as suggested in the comments, you could use Date.parse, because the heuristics work correctly in this case: require ‘date’ string = “20120723” date = Date.parse(string) Both will raise an ArgumentError if the date is not … Read more

Ruby: require vs require_relative – best practice to workaround running in both Ruby =1.9.2

A workaround for this was just added to the ‘aws’ gem so thought I’d share as it was inspired by this post. https://github.com/appoxy/aws/blob/master/lib/awsbase/require_relative.rb unless Kernel.respond_to?(:require_relative) module Kernel def require_relative(path) require File.join(File.dirname(caller[0]), path.to_str) end end end This allows you to use require_relative as you would in ruby 1.9.2 in ruby 1.8 and 1.9.1.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)