How to Use Rails Magic Methods in Plain Ruby Scripts
ruby
dev.to
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 NO