Skip to content

Commit

Permalink
Support Object#to_yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Oct 31, 2019
1 parent 1fc78d0 commit b727bf3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mrblib/core_ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Object
def to_yaml
YAML.dump self
end
end
6 changes: 6 additions & 0 deletions test/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@
assert_equal expected, actual
end

assert('YAML dump to_yaml') do
expected = YAML.dump(['foo', 'bar'])
actual = ['foo', 'bar'].to_yaml
assert_equal expected, actual
end

assert('YAML dump multi-byte') do
expected = {'foo' => 'ふー', 'bar' => 'ばー'}
actual = YAML.load(YAML.dump(expected))
Expand Down

0 comments on commit b727bf3

Please sign in to comment.