Project

General

Profile

Actions

Bug #13115

closed

`YAML.dump` outputs deperecated message even with delegated object

Added by mtsmfm (Fumiaki Matsushima) over 5 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
[ruby-core:79013]

Description

YAML.dump outputs deprecated message if it calls with delegated object
but doesn't with inherited object:

require 'yaml'
require 'delegate'

$VERBOSE = true
class Delegated < DelegateClass(Object)
  def initialize
    super(Object.new)
  end
end

puts 'YAML.dump(Delegated.new)'
YAML.dump(Delegated.new)

class Inherited < Object
end
puts 'YAML.dump(Inherited.new)'
YAML.dump(Inherited.new)

# $ ruby test.rb
# YAML.dump(Delegated.new)
# implementing to_yaml is deprecated, please implement "encode_with"
# YAML.dump(Inherited.new)

Is this intentional?

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Status changed from Open to Assigned
  • Assignee set to tenderlovemaking (Aaron Patterson)

Psych warns if to_yaml method is defined by other than psych itself, and delegated methods are defined in delegate.rb.
You can avoid the warning by undef to_yaml in class Delegated.

Updated by tenderlovemaking (Aaron Patterson) over 3 years ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF