Ruby General

Not learning Ruby is a bit like knowing how to fly a plane…on the ground.
Without Ruby, there is no Rails. Ruby is the backbone. It would be wise to have a reasonably solid Ruby foundation before adding on Rails. After that you will hit a certain point where you’ll realize that, in order to enact a desired feature for your web app, you’ll need to apply more advanced Ruby tactics. This will also come into play when trying to understand other developer’s code. As you move further down your Ruby learning path, your eyes will open wider to how much you can do with Ruby, and all the elegant and clever ways people apply Ruby to accomplish a given task. You will want to remember these. This stack is dedicated to capturing these moments of Ruby enlightenment.

Parse any date time string into a date object

08/13/20  Public, Ruby General

Use Ruby's Date #strptime method to take any date or date time object that has been created with the [#strftime](https://ruby-doc.org/stdlib-2.5.0/libdoc/date/rdoc...

1 vote - harrylevine

Benchmarking in the Rails Console

06/16/20  Public, Rails Errors, Ruby General

timing = Benchmark.measure { Post.all }

The various attributes of the object returned (Benchmark::Tms) are provided here.

Here is a sample applicati...

1 vote - harrylevine

kill all ruby processes

03/04/20  Public, Ruby General

Kill all at once

for each in `ps -eo pid,command | grep ruby | grep -v grep | awk '{print $1}' `; do kill -9 $each;done
killall −9 ruby
pkill -9 ruby
pidof ruby | xargs kill -9
ps aux | grep sidekiq | awk '{print $2}' | xargs kill
...

1 vote - harrylevine

Code review comments

01/31/20  Public, Rails Errors, Ruby General

instance variables / getters / setters

re: @redis

In general for getters and setters in our classes. Can we:

  1. limit the usage of instance variables to setters (@redis), i.e. where we are assigning things, and
  2. use an `attr_...

1 vote - harrylevine

Find and extract a recurring pattern from a string

01/09/20  Public, Ruby General

For example, let's say that you have a string containing any number of Slack user ids (i.e. <@W012A3CDE>), and you need to extract out just the user ids.

Here is the string you are startin...

1 vote - harrylevine