Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby: undefined method exclude?

Tags:

ruby

I try to use the opposite method of include? in ruby, which is "string|array.exclude?", here's my code on interactive ruby.

this = "nice"
puts this.exclude? "n"

However, it always declares an error.

Traceback (most recent call last):

    4: from C:/Ruby26-x64/bin/irb.cmd:31:in `<main>'
    3: from C:/Ruby26-x64/bin/irb.cmd:31:in `load'
    2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
    1: from (irb):14

NoMethodError (undefined method `exclude?' for "nice":String)

I researched a lot but didn't find a solution. I wonder if it only happens to me, it annoys me so much.

Could someone help me out. Thank you very much.

like image 411
Weilory Avatar asked Dec 10 '25 12:12

Weilory


1 Answers

String#exclude? is a part of activesupport gem that gets installed with every rails project. It is not included into ruby's standard library. But this method is quite simple:

def exclude?(string)
  !include?(string)
end
like image 125
Ivan Denysov Avatar answered Dec 12 '25 08:12

Ivan Denysov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!