opensource-developer
opensource-developer

Reputation: 3068

undefined method `blank?' for "123":String (NoMethodError)

I am getting this strange error for a when I am checking a class variable in ruby

undefined method `blank?' for "123":String (NoMethodError)

all I am doing is Employee.set_id.blank?

Any ideas why this could be happening?

Thanks.

Upvotes: 9

Views: 12877

Answers (2)

scorix
scorix

Reputation: 2516

Use Employee.set_id.nil? || Employee.set_id.strip.empty? instead.

String#blank? is defined in ActiveSupport

Upvotes: 7

Daniel Ruiz
Daniel Ruiz

Reputation: 620

The blank? method is defined for every Ruby object that is descendant of the Object class in activesupport gem (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/blank.rb).

This gem is part of Rails framework. However, if you still want to use this utility of activesupport in your non-Rails Ruby project, you can require it in your source files with the sentence:

require 'active_support/core_ext'

Make sure you have installed activesupport gem in your system.

Upvotes: 21

Related Questions