Featured
-
Installing RVM and Creation of Gemsets Part 2
In the last tutorial we learnt how to install RVM.
by dinesh.singh -
Installing RVM and Creating of Gemsets Part 1
Installing RVM and creating Gemsets can be difficu
by dinesh.singh -
Use pik in Windows
Managing multiple versions of Ruby on Windows can
by anirudh.rautela -
Using Bundler in Rails 2.3.x app
Managing Gems in Rails can be infuriating at times
by anirudh.rautela
Tags
Arrays and Hash In Ruby
Ruby's arrays and hashes collections having indexes. They can also be said as indexed collections.
Arrays and hashes store collections of objects which can be accessed using a key.
Both arrays and hashes grow as needed to hold...
Iterators and its usage in ruby
In Ruby, iterators are methods basically used by the collections. Collections are a set of objects. Hashes & Arrays are the example of collections. Iteration is a process by which we can get or set the elements in collections. We will discuss...
split ,find_index , map and capitalize methods in Ruby
Strings in Ruby have an instance method namely split that splits the given String and returns an array of substrings based on the separator given as an argument to it.
have a look at these examples:
gauravjhadiyal@gauravjhadiyal:~$ irb
2...
find_all method in ruby.
The find_all method has to do with arrays in Ruby.This method simply iterates through all the elements in an array and meanwhile test each of them against a test condition and finally returns an array containing all elements for which the test re...
Array Conditions and selecting specific fields to find or retrieve from database (Active records)
Array Conditions and selecting specific fields to find or retrieve from database through Active records
Array Conditions
To retrieve some specific data from the database we use the where method which gets the records in the form o...
Array and operations on array
Array is used to keep collection of objects. Array in ruby can have any type of objects together. Using array in ruby:
>> a = []
>> arr = [1, 0, 7]
>> arr[2] # => 7
>> arr.size # => 3
>> arr = ["stri...
each, collect and map in ruby
1> 'each' will loop through each element of the array and evaluate whatever is return inside the block, but it returns the original array without any change.
a = [5,10,15,20]
=> [5, 10, 15, 20]
a.each {|t| t+2}
=> [5, 10, 15, 20...
Using reject in ruby to delete elements selectively from an array
1> To delete an element from an array, use reject as shown below:
arr = ['a','b','c','d','e']
arr.reject! { |i| i.match('d')}
Result :=> ["a", "b", "c", "e"]
2> To delete particular keys from the array whose elements are ...
Applying limit and offset to array
In rails we can apply limit and offset to arrays in different ways.
1> Using "slice" method.
slice takes 2 arguments, the first one being the "starting_index" & the second one is the "number_of_elements".
syntax :-
arrayob...