Posts

Showing posts from February, 2023

sidekiq gem and implementation

  first Add gem  this gem  gem 'sidekiq' gem 'sidekiq-status' gem 'sidekiq-cron' than create in the  worker file like s ubscription_worker.rb   require 'sidekiq-status' class SubscriptionWorker include Sidekiq :: Worker include Sidekiq :: Status :: Worker def perform puts "hi-------"      # Subscription.all.each do |subscription| # if subscription.present? && subscription.expire_date.between?(Date.today, Date.today + 1.week) # send_push_notification(subscription.user_id, "your subscription will expired on #{subscription.expire_date}", "subscription reach end date notification") # end # end end def send_push_notification ( user_id , message , title ) user = User .find(user_id) PushNotification .notification( user, message, title ) end end than change the code in config/initializers/sidekiq.rb require 'sidekiq' require 'sidekiq-status...

Ruby Variable

Image
 Ruby Variable  Ruby have a four type variable - 1. Local Variable 2. Instance Variable 3. Class Variable 4. Global Variable 1. Local variable                                        A Local variable name  start with  lowercase letter(a-z) or underscore (_)  .  Local variables are not available outside the methods. There is no need to initialize the local variables . Example    age = 21 _Age = 22 2. Instance variable                                                    An instance variable name starts with a @ sign. It belongs to one instance of the class and can be accessed from any instance of the class within a method. They only have limited access to a particular instance of a class.  There is no need t...

String Methods in Ruby

Image
Ruby string Methods Explained A  string  is a sequence of one or more characters that may consist of letters, numbers, or symbols. Strings in Ruby   are objects, and unlike other languages, strings are  mutable , which means they can be changed in place instead of creating new strings.  Strings in Ruby by default are mutable and can be changed in place or a new string can be returned from a method. .length length  is a String class method in Ruby which is used to find the character length of the given string. "Hello".length =>5 .Empty It is a String class method in Ruby which is used to check whether the string length is zero or not. "hello".empty =>false "!".empty =>false " ".empty =>false "".empty =>true .Concatenation class This is use to concatenate two strings together.It is define +  symbol. "Hello " + "how are you?" Output:=>"Hello how are you?" .count I n this...

Array Methods in ruby

Image
  Arrays What is an Array? An  array  is an ordered list of elements that can be of any type. You can define an array by placing a list of elements between brackets like so: Most Common Ruby Array Methods  You Should Know Common Array Methods A new array can be created by using the literal constructor [] . Arrays can contain different types of objects. For example, the array below contains an  Integer , a  String  and a Float:  Our array will be as follows: array = [ 1,2 , 3,4,5 ] .length The .length method is used to the number of elements in your array and returns the count: array.length #=>array -> [1,2,3,4,5] =>5 .first The .first method accesses the first element of the given array and the element start at index of  0: array.first #=>array -> [1,2,3,4,5] =>1 .last The .last method accesses the last element of the given array: array.last #=>array -> [1,2,3,4,5] =>5 .take The .take method returns th...