diff --git a/core/range.rbs b/core/range.rbs new file mode 100644 index 0000000..b83d58e --- /dev/null +++ b/core/range.rbs @@ -0,0 +1,17 @@ +# FIXME: mruby/c only supports Range[Integer] only +class Range[out Elem] < Object + def ===: (untyped other) -> bool + def self.===: (untyped other) -> bool + + def first: () -> Elem + + def last: () -> Elem + + def exclude_end?: () -> bool + + def inspect: () -> String + def self.inspect: () -> String + + alias to_s inspect + alias self.to_s self.inspect +end diff --git a/core/string.rbs b/core/string.rbs index f114871..fe8142d 100644 --- a/core/string.rbs +++ b/core/string.rbs @@ -26,17 +26,15 @@ class String < Object def <<: (String) -> String - # TODO: Range def slice: (Integer nth) -> String? | (Integer nth, Integer len) -> String? - # | (Range range) -> String? + | (Range[Integer] range) -> String? alias [] slice - # TODO: Range def []=: (Integer nth, String val) -> String | (Integer nth, Integer len, String val) -> String - # | (Range range, String val) -> String + | (Range[Integer] range, String val) -> String def b: () -> String diff --git a/test/range.rb b/test/range.rb new file mode 100644 index 0000000..c26d2bc --- /dev/null +++ b/test/range.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# rubocop:disable Lint/Void +# rubocop:disable Style/CaseEquality +# rubocop:disable Lint/BinaryOperatorWithIdenticalOperands + +0..10 + +(0..10) === (0..10) + +(0..10).first + +(0..10).last + +(0...10).exclude_end? + +(0..10).inspect +Range.inspect + +(0..10).to_s +Range.to_s + +# rubocop:enable all diff --git a/test/string.rb b/test/string.rb index ae593cd..dbfc076 100644 --- a/test/string.rb +++ b/test/string.rb @@ -40,12 +40,15 @@ 'abcdef'.slice 2 'abcdef'.slice 2, 3 +'abcdef'.slice 2..4 'abcdef'[3] 'abcdef'[3, 3] +'abcdef'[3...6] 'abcdef'[3] = 'D' 'abcdef'[3, 3] = 'defghi' +'abcdef'[3...6] = 'defghi' 'abcdef'.b