# Ruby vs Rails

DevFeed: [Ruby vs Rails](<https://devfeed.tech/articles/ruby-vs-rails-28306.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/ruby/2020/02/10/ruby-vs-rails.html>)

Author: Fuzzygroup

Published: 2020-02-10T00:00:00Z

Content type: article

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Rails](<https://devfeed.tech/topics/rails.md>), [Kafka](<https://devfeed.tech/topics/kafka.md>), [X (Twitter)](<https://devfeed.tech/topics/twitter.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [data](<https://devfeed.tech/tags/data.md>), [kafka](<https://devfeed.tech/tags/kafka.md>), [rails](<https://devfeed.tech/tags/rails.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [sample](<https://devfeed.tech/tags/sample.md>), [vs](<https://devfeed.tech/tags/vs.md>)

## AI overview

The article explains Rails-specific methods that can cause failures when Ruby code runs outside Rails. Using a background daemon that streams Twitter data to Kafka, it examines the undefined `blank?` method in pure Ruby and the Rails-provided `second` method on arrays, then shows Ruby-compatible alternatives.

## Source excerpt

I always find it interesting when I hit a Rails-ism when I'm working in a pure Ruby context. I define a Rails-ism as something that is one way in Ruby and another way in Rails. In this case I'm writing a simple background daemon which is going to stream data out of the Twitter sample stream and commit to Kafka for downstream processing. Here's the first thing that bit me: TOPIC = ENV['TOPIC'] if TOPIC.blank? puts "No topic specified; exiting" exit end And this gave an immediate failure: ❯ TOPIC=twitter RAILS_ENV=development ruby kafka_loader.rb Traceback (most recent call last): kafka_loader.rb:19:in `<main>': undefined method `blank?' for "twitter":String (NoMethodError) The easiest way to understand something like this is to test it in irb. The irb tool is the underlying engine in rails console ("rails c") but without your application specific classes loaded in so it is just pure ruby. Here's how you would test something like this in irb: 2.7.0 :001 > "".blank? Traceback (most recent call last): 16: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/friendly_errors.rb:123:in `with_friendly_errors' 15: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.2/libexec/bundle:46:in `block in <top (required)>' 14: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/cli.rb:24:in `start' 13: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start' 12: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/cli.rb:30:in `dispatch' 11: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch' 10: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command' 9: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run' 8: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/cl