Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
jbwiv opened this Issue · 1 comment

2 participants

@jbwiv
 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]
@BanzaiMan
Owner

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.