Skip to content

Adding a method to eigenclass doesn't work properly. Works in cruby #596

@d1rewolf

Description

@d1rewolf
 class X
  def total_cost 
    99
  end
  alias_method :old_dup, :dup
  def dup
    c = self.old_dup
    class << c
      attr_reader :total_cost
      public
      def initialize_copy(orig)
        puts "Inside initialize_copy"
        @total_cost = orig.total_cost
      end
    end
    c.initialize_copy(self)
    return c
  end
end

 an_x = X.new
 an_x.dup
$ ruby /tmp/t.rb 
Inside initialize_copy
$ jruby /tmp/t.rb 
NoMethodError: private method `initialize_copy' called for #<X:0x300cd634>
     dup at /tmp/t.rb:16
  (root) at /tmp/t.rb:22
$ jruby -v
jruby 1.7.3 (1.9.3p385) 2013-02-21 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_03-b04 [linux-amd64]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions