Rails Upgrading a project

When changing Rails versions, it's best to move slowly, one minor version at a time The process should go as follows: Write tests and make sure they pass. Move to the latest patch version after your current version. Fix tests and deprecated features. Move to the latest patch version of the next minor version. Repeat this process until you reach your target Rails version Rails 6 requires Ruby 2.5.0 or newer. Rails 5 requires Ruby 2.2.2 or newer. Rails 4 prefers Ruby 2.0 and requires 1.9.3 or newer. Rails 3.2.x is the last branch to support Ruby 1.8.7. Rails 3 and above require Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially. You should upgrade as early as possible.   Rails provides the app:update command ( rake rails:update on 4.2 and earlier). After updating the Rails version in the Gemfile , run this command. This will help you with the creation of new files and changes of old files in an interactive session.  

Ruby 2.5 Major Changes

1. rescue/else/ensure are allowed inside do/end blocks without begin/end 2. Print backtrace and error message in reverse order (experimental) 3. Kernel#yield_self           2.yield_self { |n| n * 10 } #=> 20           names = ['Alice', 'Bob']            names.join(', ').yield_self { |s| "(#{s})" }           #=> "(Alice, Bob)" 4. String#delete_prefix/delete_suffix 5. Array#prepend/append as aliases of unshift/push 6. Hash#transform_keys/transform_keys!

Prime Number with out Prime Class

a = [1,4,5,12,9,5,3,5] class Array   def prime_numbers   end end class Integer   def prime?     return if self <= 1     (2..Math.sqrt(self).ceil).none? { |i| (self % i).zero? }   end end  a.prime_numbers => [5, 5, 3, 5]

Ruby's class_eval & instance_eval. Is it that confusing?

We can do class_eval & instance_eval using following syntax, In this example, class_eval? method can be accessed my any objects of the String class. Where as instance_eval? method can be accessed by only String class.  More clearly, class_eval creates instance methods, but instance_eval creates class methods or it can be applied to only one object at a time. [3] pry(main)> String.class_eval? NoMethodError: undefined method `class_eval?' for String:Class Did you mean?  class_eval from (pry):3:in `<main>' [4] pry(main)> String.instance_eval? => true [5] pry(main)> => true my_string = "This is a string" For example you can simply do like below as any string is an object of String Class [5] pry(main)>  my_string .class_eval? => true But you can not do  [7] pry(main)> my_string.instance_eval? NoMethodError: undefined method `instance_eval?' for "This is a string":String

Install Nginx & passenger in CentOS 6.x

Nginx Installation First of all, nginx is not a repo available under yum. But you can install epel, through which install nginx. 1. Install EPEL yum install epel-release OR download sudo rpm -iUvh epel-release-6-8.noarch.rpm 2. Check EPEL repo yum repolist You should get HPIT-v2cloud-RedHat-nover-x86_64                  HPIT-v2cloud-RedHat-nover-x86_64  0 HPIT-v2cloud-nodist-nover-noarch                      HPIT-v2cloud-nodist-nover-noarch   22 HPIT-v2cloud-nodist-nover-x86_64                     HPIT-v2cloud-nodist-nover-x86_64    3 RedHat-6.5Server-x86_64-Server                        RedHat Linux 6.5Server - os - x86_64 - Server RedHat-updates-QPK-6Server-x86_64                RedHat-updates-QPK-6Server-x86_64 centos-gluster37                                                    CentOS-6Server - Gluster 3.7 *epel                                                                     E

Installation guide for RVM Multiuser

When I was trying to install RVM for multiuser, There was no proper guidelines for it. So I decided to create one. Please follow the below steps to install RVM for multiuser. 1. Install mpapis public key sudo gpg2 --keyserver hkp:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 or curl -sSL | sudo gpg2 --import 2. Install RVM for Multiuser curl -L | sudo bash -s stable 3. Load RVM to Environment echo "[[ -s /usr/local/rvm/scripts/rvm ]] && source /usr/local/rvm/scripts/rvm" >> ~/.bashrc  source .bashrc 4. Reload shell configuration & test Close out your current shell or terminal session and open a new one (preferred). You may load RVM with the following command: source /usr/local/rvm/scripts/rvm 5. Final Testing If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command wh

Ruby Proc & Lamda - A close look

One of the core concepts about Ruby that a programmer should remember is that blocks are not objects. It is possible to convert them into objects by wrapping them inside the “Proc” class instance. The “Proc” and “Lambda” classes are probably the most awesome aspects of Ruby and need to be used well in order to get the desired results. Not much of knowledge is available on how to use Procs and Lambdas and what the differences between both are. I’d like to take a stab at how we can differentiate between Procs and Lambdas with a couple of thoughts below. 1. Proc doesn’t check the parameters passed, but Lambda does > proc1 = { |a, b| a + 5 } >      # call with only one parameter => 7                    # no error, unless the block uses the 2nd parameter    > lambda1 = lambda { |a, b| a + 5 } > ArgumentError: wrong number of arguments (1 for 2) Proc will throw error only if the block uses the second param. >