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):14NoMethodError (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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With