Skip to content

Commit

Permalink
Merge pull request #67 from hanachin/update_integer_to_s
Browse files Browse the repository at this point in the history
Update Integer#to_s signature and add test
  • Loading branch information
soutaro committed Nov 10, 2019
2 parents 44cdc61 + 63e3ae6 commit f51b86f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/ruby/signature/test/hook.rb
Expand Up @@ -220,7 +220,13 @@ def delegation(name, method_types, method_name)
end

method = hook.call(self, METHOD, name)
prepended = hook.call(self, CLASS).ancestors.include?(hook.instance_module) || hook.call(self, SINGLETON_CLASS).ancestors.include?(hook.singleton_module)
klass = hook.call(self, CLASS)
singleton_klass = begin
hook.call(self, SINGLETON_CLASS)
rescue TypeError
nil
end
prepended = klass.ancestors.include?(hook.instance_module) || singleton_klass&.ancestors&.include?(hook.singleton_module)
result = if prepended
method.super_method.call(*args, &block)
else
Expand Down
38 changes: 36 additions & 2 deletions stdlib/builtin/integer.rbs
Expand Up @@ -427,8 +427,42 @@ class Integer < Numeric
#
#
# Also aliased as: [inspect](Integer.downloaded.ruby_doc#method-i-inspect)
def to_s: (?Integer base) -> String

def to_s: () -> String
| (2) -> String
| (3) -> String
| (4) -> String
| (5) -> String
| (6) -> String
| (7) -> String
| (8) -> String
| (9) -> String
| (10) -> String
| (11) -> String
| (12) -> String
| (13) -> String
| (14) -> String
| (15) -> String
| (16) -> String
| (17) -> String
| (18) -> String
| (19) -> String
| (20) -> String
| (21) -> String
| (22) -> String
| (23) -> String
| (24) -> String
| (25) -> String
| (26) -> String
| (27) -> String
| (28) -> String
| (29) -> String
| (30) -> String
| (31) -> String
| (32) -> String
| (33) -> String
| (34) -> String
| (35) -> String
| (36) -> String
# Returns `int` truncated (toward zero) to a precision of `ndigits`
# decimal digits (default: 0).
#
Expand Down
43 changes: 43 additions & 0 deletions test/stdlib/Integer_test.rb
@@ -0,0 +1,43 @@
class IntegerTest < StdlibTest
target Integer
using hook.refinement

def test_to_s
1.to_s
1.to_s(2)
1.to_s(3)
1.to_s(4)
1.to_s(5)
1.to_s(6)
1.to_s(7)
1.to_s(8)
1.to_s(9)
1.to_s(10)
1.to_s(11)
1.to_s(12)
1.to_s(13)
1.to_s(14)
1.to_s(15)
1.to_s(16)
1.to_s(17)
1.to_s(18)
1.to_s(19)
1.to_s(20)
1.to_s(21)
1.to_s(22)
1.to_s(23)
1.to_s(24)
1.to_s(25)
1.to_s(26)
1.to_s(27)
1.to_s(28)
1.to_s(29)
1.to_s(30)
1.to_s(31)
1.to_s(32)
1.to_s(33)
1.to_s(34)
1.to_s(35)
1.to_s(36)
end
end

0 comments on commit f51b86f

Please sign in to comment.