How to Use Rails Magic Methods in Plain Ruby Scripts
Very often I find myself writing small, standalone Ruby scripts. Maybe it's a web scraper, a small background worker, or a quick Sinatra API. I start typing out my code, and naturally, I write some...

Source: DEV Community
Very often I find myself writing small, standalone Ruby scripts. Maybe it's a web scraper, a small background worker, or a quick Sinatra API. I start typing out my code, and naturally, I write something like this: if my_variable.present? puts "We have data!" end And immediately, my script crashes with NoMethodError: undefined method 'present?' for nil:NilClass. This is the moment every Ruby developer realizes a shocking truth: Methods like .present?, .blank?, and 3.days.ago are NOT part of the Ruby language. They are part of Rails. But what if you want to use these awesome methods without generating a massive, heavy Rails application? You can. All of these "magic" methods live inside a single gem called ActiveSupport. You can easily extract it and use it in any plain Ruby script. Here is how to do it. STEP 1: The Setup First off, let's install the gem. If you are using a Gemfile for your script, just add this: source 'https://rubygems.org' gem 'activesupport' Run bundle install. If you