Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Open
jbwiv opened this Issue Mar 19, 2013 · 3 comments

Comments

Projects
None yet
5 participants

jbwiv commented Mar 19, 2013

 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]
Owner

BanzaiMan commented Mar 24, 2013

Seems like public is not effective in this case. We do need to fix it, but there is a workaround. After redefining initialize_copy, do:

public :initailize_copy

Still seems to be an issue with current rubies:

ruby 1.9.3p550 (2014-10-27) [x86_64-darwin14.5.0]
Inside initialize_copy

ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin14]
Inside initialize_copy

ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14]
Inside initialize_copy

jruby 1.7.24 (1.9.3p551) 2016-01-20 bd68d85 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_51-b16 +jit [darwin-x86_64]
NoMethodError: private method `initialize_copy' called for #<X:0x6f7fd0e6>
     dup at issues/596.rb:20
  (root) at issues/596.rb:26

jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.51-b03 on 1.8.0_51-b16 +jit [darwin-x86_64]
NoMethodError: private method `initialize_copy' called for #<X:0x2b9627bc>
    dup at issues/596.rb:20
  <top> at issues/596.rb:26

@enebo enebo added the JRuby 9000 label Feb 17, 2017

Owner

kares commented May 22, 2017

confirmed (still) on 9.1.10.0 :

NoMethodError: private method `initialize_copy' called for #<X:0x5bb21b69>
Did you mean?  initialize_clone
               initialize
               initialize_dup
     dup at x.rb:16
  <main> at x.rb:22

UPDATE: also public :initialize_copy as a work-around still works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment