7

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.)

tadman
  • 208,517
  • 23
  • 234
  • 262
Zack Xu
  • 11,505
  • 9
  • 70
  • 78
  • 9
    The commit was merged on June 19. Ruby 2.4.1 was released in March, 3 months before `String#delete_prefix` was even written. So, it cannot possibly be in there. There seems to be a bug in Ruby-Doc's build scripts. Note: it always helps to check the documentation that comes with the Ruby you have actually installed instead of looking on third-party sites. – Jörg W Mittag Sep 13 '17 at 13:31
  • 1
    After doing `rvm install ruby-head`, the methods `String#delete_prefix` and `String#delete_suffix` are available. Thanks – Zack Xu Sep 13 '17 at 14:54

0 Answers0