From 7e91eb413fededa196c3ace3e49043a6c9247e0f Mon Sep 17 00:00:00 2001 From: tufusa Date: Fri, 22 May 2026 23:17:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20`Range`=20=E3=82=92=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/range.rbs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 core/range.rbs 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 From c55f25d96156c6e4a12fce7aea832ece5bb51c8c Mon Sep 17 00:00:00 2001 From: tufusa Date: Fri, 22 May 2026 23:17:38 +0900 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/range.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/range.rb 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 From d4de6b949bbffdcf7814bd311383c494d9e43826 Mon Sep 17 00:00:00 2001 From: tufusa Date: Fri, 22 May 2026 23:23:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20`String#slice`,=20`String#[]=3D`=20?= =?UTF-8?q?=E3=81=AB=20`Range`=20=E5=BC=95=E6=95=B0=E3=81=AE=E3=82=AA?= =?UTF-8?q?=E3=83=BC=E3=83=90=E3=83=BC=E3=83=AD=E3=83=BC=E3=83=89=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/string.rbs | 6 ++---- test/string.rb | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) 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/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