Skip to content

Commit 2bf2606

Browse files
authored
Merge pull request #2107 from znz/add-to_yaml
Add Object#to_yaml
2 parents 2b63c7f + 1c9fb49 commit 2bf2606

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

stdlib/psych/0/core_ext.rbs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%a{annotate:rdoc:skip}
2+
class Object
3+
# <!--
4+
# rdoc-file=ext/psych/lib/psych/core_ext.rb
5+
# - to_yaml(options = {})
6+
# -->
7+
# Convert an object to YAML. See Psych.dump for more information on the
8+
# available `options`.
9+
#
10+
def to_yaml: (?indentation: Integer, ?line_width: Integer, ?canonical: bool, ?header: bool) -> String
11+
| [IO] (IO, ?indentation: Integer, ?line_width: Integer, ?canonical: bool, ?header: bool) -> IO
12+
end

test/stdlib/psych_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,21 @@ def test_dump
7575
Psych, :dump, [1], indentation: 3, line_width: 30, canonical: true, header: true
7676
)
7777
end
78+
79+
def test_to_yaml
80+
assert_send_type(
81+
"() -> ::String",
82+
[1], :to_yaml
83+
)
84+
85+
assert_send_type(
86+
"(::StringIO) -> ::StringIO",
87+
[1], :to_yaml, StringIO.new()
88+
)
89+
90+
assert_send_type(
91+
"(indentation: ::Integer, line_width: ::Integer, canonical: bool, header: bool) -> ::String",
92+
[1], :to_yaml, indentation: 3, line_width: 30, canonical: true, header: true
93+
)
94+
end
7895
end

0 commit comments

Comments
 (0)