2015
-
Lets create a new class Accessor where we will define our brand new class method accessor and we will define getter and setter methods using class_eval: Now, lets use our accessor method instead of attr_accessor:
-
Get the sum of an array (using #inject or #reduce):
-
Let’s concatenate strings : Let’s declare an array of size 5, prefilled with nil: An Array of size 5, prefilled with empty Hash: An array of letters a to z: Size of the above letters array: Concate two array: Union operation in above arrays: Intersection (take only common elements) operation in above arrays: Join elements…
-
Install ElasticSearch : — For Ubuntu 14.04 Install Java Default Runtime & JDK Install ElasticSearch from Debian software package Test ElasticSearch install We will get a response like this: We will be using Searchkick – a ruby gem which works as a wrapper on top of ElasticSearch and provides robust searching as well as many…
-
BLOCKS Any code surrounded by curly braces {} or do…end is a block. 5.times { print “I’m a block.” } 5.times do print “I’m a block” end In a block, there will be lines of codes and yield allows you to “inject” that code at some place into a function. So if you want your…