NoMethodError: undefined method "delete_prefix" String class (Ruby 2.4.1)

1.9k Views Asked by At

I'm using the latest Ruby (version 2.4.1)

I see there's a method String#delete_prefix as defined in https://ruby-doc.org/core-2.4.1/String.html#method-i-delete_prefix

But in irb, this method doesn't exist for some reason:

2.4.1 :030 > c="_abc_xyz"
=> "_abc_xyz"
2.4.1 :031 > c.delete_prefix("_")
NoMethodError: undefined method `delete_prefix' for "_abc_xyz":String
from (irb):31
from /Users/jonsmith/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>'
2.4.1 :032 >

What's going on here?!

(The above can be achieved by c.gsub(/^_/, ''), but I'm wondering why delete_prefix and delete_suffix don't exist contrary to Ruby documentation.)

0

There are 0 best solutions below