Skip to content

Commit e16906e

Browse files
transclaude
andcommitted
Review String methods: redefine lchomp as delete_prefix alias
- Redefine String#lchomp/lchomp! as aliases for delete_prefix/delete_prefix! - 72 String methods reviewed; all others kept as-is - No deprecations needed — unique text utilities throughout Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 61d43c2 commit e16906e

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Changes:
100100
* Deprecate `Enumerable#map_with_index` (use `Enumerable#map.with_index`).
101101
* Deprecate `Enumerable#mash` (use `Enumerable#graph` instead).
102102
* Deprecate `Enumerable#uniq_by` (use `Enumerable#uniq(&block)`, Ruby 1.9.2+).
103+
* Redefine `String#lchomp` / `#lchomp!` as aliases for `delete_prefix` / `delete_prefix!`.
103104
* Fix dead requires for removed `kernel/singleton_class` in Proc and Kernel.
104105
* Remove misplaced `applique/file_helpers` from core (test infrastructure).
105106
* Drop unused `test_files` directive from gemspec. (PR#301)

lib/core/facets/string/lchomp.rb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
class String
22

3-
# Left chomp.
3+
# Left chomp. Alias for #delete_prefix.
44
#
55
# "help".lchomp("h") #=> "elp"
66
# "help".lchomp("k") #=> "help"
77
#
88
# CREDIT: Trans
99

1010
def lchomp(match)
11-
if index(match) == 0
12-
self[match.size..-1]
13-
else
14-
self.dup
15-
end
11+
delete_prefix(match)
1612
end
1713

18-
# In-place left chomp.
14+
# In-place left chomp. Alias for #delete_prefix!.
1915
#
20-
# "help".lchomp("h") #=> "elp"
21-
# "help".lchomp("k") #=> "help"
16+
# s = "help"
17+
# s.lchomp!("h") #=> "elp"
18+
# s #=> "elp"
2219
#
2320
# CREDIT: Trans
2421

2522
def lchomp!(match)
26-
if index(match) == 0
27-
self[0...match.size] = ''
28-
self
29-
end
23+
delete_prefix!(match)
3024
end
3125

3226
end
33-

0 commit comments

Comments
 (0)