Skip to content

Commit 96cc4ba

Browse files
committed
Add deprecation warning to ENV.index
1 parent 15cff65 commit 96cc4ba

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Bug fixes:
6363
* Fixed `printf` should raise error when not enough arguments for positional argument.
6464
* Removed "shadowing outer local variable" warning.
6565
* Fixed parameter conversion to `String` in ENV methods.
66+
* Fixed deprecation warning when `ENV.index` is called.
6667

6768
Compatibility:
6869

spec/tags/core/env/index_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/ruby/truffleruby/core/env.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,20 @@ def values_at(*params)
201201
end
202202

203203
def index(value)
204-
value = StringValue(value);
205-
each do |k, v|
206-
return k if v == value
207-
end
208-
nil
204+
warn 'warning: ENV.index is deprecated; use ENV.key'
205+
key(value)
209206
end
210207

211208
def invert
212209
to_hash.invert
213210
end
214211

215212
def key(value)
216-
index(value)
213+
value = StringValue(value);
214+
each do |k, v|
215+
return k if v == value
216+
end
217+
nil
217218
end
218219

219220
def keys
@@ -311,7 +312,7 @@ def assoc(key)
311312
def rassoc(value)
312313
value = Truffle::Type.rb_check_convert_type(value, String, :to_str)
313314
return nil if value.nil?
314-
key = index(value)
315+
key = key(value)
315316
key ? [key, value] : nil
316317
end
317318

0 commit comments

Comments
 (0)