Skip to content

Modify private class methods#455

Closed
yhirano55 wants to merge 1 commit intoctran:developfrom
yhirano55:modify_private_class_methods
Closed

Modify private class methods#455
yhirano55 wants to merge 1 commit intoctran:developfrom
yhirano55:modify_private_class_methods

Conversation

@yhirano55
Copy link
Copy Markdown
Contributor

I found wrong definitions.

This does not work:

[1] pry(main)> module Foo
[1] pry(main)*   private
[1] pry(main)*   def self.say
[1] pry(main)*     __method__
[1] pry(main)*   end
[1] pry(main)* end
=> :say
[2] pry(main)> Foo.say
=> :say

We should define private_class_method or define inside its singleton class block:

[3] pry(main)> module Bar
[3] pry(main)*   def self.say
[3] pry(main)*     __method__
[3] pry(main)*   end
[3] pry(main)*   private_class_method :say
[3] pry(main)* end
=> Bar
[4] pry(main)> Bar.say
NoMethodError: private method `say' called for Bar:Module
from (pry):14:in `__pry__'
[5] pry(main)> module Baz
[5] pry(main)*   class << self
[5] pry(main)*     private
[5] pry(main)*     def say
[5] pry(main)*       __method__
[5] pry(main)*     end
[5] pry(main)*   end
[5] pry(main)* end
=> :say
[6] pry(main)> Baz.say
NoMethodError: private method `say' called for Baz:Module
from (pry):23:in `__pry__'

@ctran
Copy link
Copy Markdown
Owner

ctran commented May 1, 2017

Could you explain a bit the reasons for this change?

@yhirano55
Copy link
Copy Markdown
Contributor Author

Thanks for your reviewing.

The current code expects private, but as a behavior it does not become private (*). So we had better to remove private keyword in lib/annotate/annotate_routes.rb, or to modify correct syntax🤓

@yhirano55
Copy link
Copy Markdown
Contributor Author

@ctran Please re-review, or close this request if you don't need (It's no problem for me)

@ctran
Copy link
Copy Markdown
Owner

ctran commented Jun 2, 2017

@yhirano55 Thanks for the education. You're correct that "private" doesn't work in this case. I'll remove the private keyword since it's less intrusive.

@ctran ctran closed this Jun 2, 2017
@yhirano55 yhirano55 deleted the modify_private_class_methods branch June 2, 2017 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants