Skip to content

Commit f105514

Browse files
bonus methods
1 parent a05f49e commit f105514

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/code/object/string.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ def call(**args)
4343
when "starts_with?"
4444
sig(args) { String }
4545
code_starts_with?(code_value)
46+
when "start_with?"
47+
sig(args) { String }
48+
code_start_with?(code_value)
49+
when "ends_with?"
50+
sig(args) { String }
51+
code_ends_with?(code_value)
52+
when "end_with?"
53+
sig(args) { String }
54+
code_end_with?(code_value)
4655
when "first"
4756
sig(args) { Integer.maybe }
4857
code_first(code_value)
@@ -95,6 +104,19 @@ def code_starts_with?(value)
95104
Boolean.new(raw.start_with?(code_value.raw))
96105
end
97106

107+
def code_start_with?(value)
108+
code_starts_with?(value)
109+
end
110+
111+
def code_end_with?(value)
112+
code_value = value.to_code
113+
Boolean.new(raw.end_with?(code_value.raw))
114+
end
115+
116+
def code_ends_with?(value)
117+
code_end_with?(value)
118+
end
119+
98120
def code_plus(other)
99121
code_other = other.to_code
100122
String.new(raw + code_other.to_s)

spec/code_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@
190190
%w[9975×14÷8 17456.25],
191191
%w["Hello".starts_with?("He") true],
192192
%w["Hello".starts_with?("lo") false],
193+
%w["Hello".start_with?("He") true],
194+
%w["Hello".start_with?("lo") false],
195+
%w["Hello".ends_with?("lo") true],
196+
%w["Hello".ends_with?("He") false],
197+
%w["Hello".end_with?("lo") true],
198+
%w["Hello".end_with?("He") false],
193199
%w[:Hello.include?(:H) true],
194200
%w[:admin? :admin?],
195201
%w[:hello :hello],

0 commit comments

Comments
 (0)