Total Blog Views: 38
Blog Status: publish
Created By: swazahmad Created at: 08-05-2021
include? :
a = [ "apple", "dog", "cat"]
a.include?("apple") => true
flatten:
It returns
The Above Method is basically use to remove brackets from array of array in ruby.
a = [ 22, 31, [14, [55, 6] ] ]
a.flatten ==> [22, 31, 14, 55, 6]
a = [ "apple", "ball", "cat", "dog"]
a.collect {|x| x + "!" }
["apple!", "ball!", "cat!", "dog!"]
join() :
The join() function returns a string created by converting every element of the array to a string and separates them by a SepString.
[ "1", "2", "3" ].join => "123"
[ "1", "2", "3" ].join(",") => "1,2,3"
uniq() :
As Method defined meaning Itself Provide a new unique array by Removing duplicate entries.
a = [ "a", "a", "b", "b", "c" ]
a.uniq => ["a", "b", "c"]
finite? :
It returns the value "true" if flt is a valid IEEE floating-point number.
flt.finite? → true or false
infinite? :
It returns the value 'nil', '-1', or '+1' depending on whether flt is 'finite', '-infinity', or '+infinity'.
(0.0).infinite? → nil
(-1.0/0.0).infinite? → -1
(+1.0/0.0).infinite? → 1
round :
It returns a number rounded to the nearest integer or equivalent to.
1.4.round → 1
sum :
Sum is used to add the all entries into On we can use sum method in several ways in active record, array, sum of two string.
[1,2,3].sum → 6
pluck :
The Pluck methods return an Array of records we requested for example, if we need to pluck name from users Table we can write below.
User.pluck(:name) ===> ['sample 1', 'sample 2']
empty:
Empty Method is basically use to check the object is having the value or not.
a = 'swaz'
a.empty? => false
b = ''
b.empty? => true
gsub:
The gsub method replaces every reference of
"We are programmer".gsub("are", "are good")
"We are good programmer"
Conclusion :
With several ruby methods available,
Thank you so much for Reading .
we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.
© Copyright Shadbox. All Rights Reserved
Rate Blog :
Share on :
Do you have any blog suggestion? please click on the link