Re: How does the private method work?
bit,
I’m not quite sure what you are asking but …
“private” is not a keyword but, instead, a method. So one can dynamically make other methods, uh, private or not.
Two links of interest might be
https://medium.com/@tjoye20/ruby-access-control-basics-public-vs-private-vs-protected-methods-7788b26e04a7
https://gnuu.org/2011/01/01/rubys-private-keyword-is-not-heresy/
Ralph
Tuesday, April 17, 2018, 3:21:32 AM, you wrote:
Thanks Ralph. I understand what “private” as an OOP construct does. But as Christian mentioned, I am looking at how ruby interprets it. For instance, I see ruby also allows this
def first_method
end
def second_method
end
private :first_method, :second_method
Is the above private and the private I mentioned in my initial question, the same ? If not, how are they not the same ?
···
On Tue, Apr 17, 2018 at 1:27 PM, Ralph Shnelvar ralphs@dos32.com wrote:
bit,
The idea behind “private” in most/all OOP languages is that you are telling other developers and/or yourself to not use this/these methods in the future as
-
the interface to the method may change
-
the side effects may change
When you declare a method, e.g.
def some_method(arg1, arg2, arg3)
#Do something
#return another_thing
end
you are establishing a “contract” between your object and the outside world.
By declaring the method private you are telling the world “Don’t call this! I may not implement this functionality at all in future versions!”
Ralph
Tuesday, April 17, 2018, 1:16:08 AM, you wrote:
Hello,
I just saw one developer do this in his code :
private if some_condition?
def first_method
end
I was wondering how the private method works. How does it figure out which methods to mark private ?
It would be nice if someone could explain this or point me to appropriate resources on the web.
Ralph
Ralph