Projects

Ticket #204 (new defect)

Opened 3 years ago

Last modified 8 months ago

Private methods redefined public are still in private_methods

Reported by: vincent.isambart@… Owned by: eloy.de.enige@…
Priority: blocker Milestone: MacRuby 1.0
Component: MacRuby Keywords: #reduction
Cc:

Description

All classes have a private puts method. However, if you redefine publically puts in a class, puts is still in its private methods list (but it's also in the public methods). It should only be in the public methods.

class A; end
p A.private_instance_methods.grep(/puts/)
p A.public_instance_methods.grep(/puts/)
class A
  def puts
  end
end
p A.private_instance_methods.grep(/puts/)
p A.public_instance_methods.grep(/puts/)

displays:

[:puts]
[]
[:puts]
[:puts]

instead of: (Ruby 1.9)

[:puts]
[]
[]
[:puts]

Attachments

204.rb Download (326 bytes) - added by emil@… 14 months ago.
reduction
204.2.rb Download (429 bytes) - added by emil@… 14 months ago.
reduction

Change History

  Changed 3 years ago by eloy.de.enige@…

Actually, it seems that this only happens with methods from Kernel. That's where puts comes from for instance. See:

#!/usr/local/bin/macruby

module NonKernel
  private
  def foo; end
end

class A
  include NonKernel
end
p A.private_instance_methods.grep(/puts|foo/)
p A.public_instance_methods.grep(/puts|foo/)

class A
  def puts
  end
  
  def foo
  end
end

p A.private_instance_methods.grep(/puts|foo/)
p A.public_instance_methods.grep(/puts|foo/)

Displays:

[:foo, :puts]
[]
[:puts]
[:puts, :foo]

I think it's related to changes to Kernel which also cause the problem as described in ticket #188, but I think this warrants it's own test case for known bugs. Shall I add one?

Changed 14 months ago by emil@…

reduction

  Changed 14 months ago by emil@…

error exists on trunk rev 4976

Changed 14 months ago by emil@…

reduction

  Changed 14 months ago by eloy.de.enige@…

  • keywords #reduction added

  Changed 14 months ago by lsansonetti@…

  • milestone set to MacRuby 1.0

  Changed 14 months ago by eloy.de.enige@…

  • owner changed from lsansonetti@… to eloy.de.enige@…

follow-up: ↓ 7   Changed 9 months ago by lsansonetti@…

  • milestone changed from MacRuby 1.0 to MacRuby Later

This problem does not seem critical for 1.0, moving to Later.

in reply to: ↑ 6   Changed 8 months ago by christian@…

Replying to lsansonetti@…:

This problem does not seem critical for 1.0, moving to Later.

I disagree: this bug causes 'bundler exec' to fail with the message 'Could not find task "exec".' Bundler is a very important gem for me, and of course a requirement for Rails 3.

'bundler exec' fails because the #exec method is both public and private on the Kernel module:

Kernel.public_methods & Kernel.private_methods
=> [:load_plist, :load_bridge_support_file, :binding, :lambda, :proc, :framework, :autoload?, :autoload, :require, :load, :abort, :exit, :sleep, :spawn, :system, :exit!, :fork, :exec, :trap, :rand, :srand, :getpass, :test, :display, :p, :`, :readlines, :select, :readline, :gets, :puts, :putc, :print, :printf, :open, :syscall, :at_exit, :untrace_var, :trace_var, :caller, :loop, :throw, :catch, :local_variables, :global_variables, :raise, :fail, :block_given?, :iterator?, :eval, :warn, :Array, :String, :Float, :Integer, :format, :sprintf]

Bundler uses the Thor gem to define its command line, and Thor excludes private or protected methods from command-line parsing:

    def public_method?(instance) #:nodoc:
      collection = instance.private_methods + instance.protected_methods
      (collection & [name.to_s, name.to_sym]).empty?
    end

(From  https://github.com/wycats/thor/blob/master/lib/thor/task.rb#L69 )

This implementation doesn't seem wrong to me, though it would obviously work if they had checked for inclusion in #public_methods instead.

For the same reason the 'bundler open' command also fails with the same message.

  Changed 8 months ago by lsansonetti@…

  • milestone changed from MacRuby Later to MacRuby 1.0

Sorry, I didn't know this was breaking Bundler. Moving to 1.0 milestone.

Note: See TracTickets for help on using tickets.