Questions tagged [private-methods]

285 questions
6
votes
3 answers

Blocks vs private methods?

What are the disadvantages of using a block to define a private method within a method, instead of using a real private method? Is there any apart from not being able to call the method from somewhere else? Example: -(NSDictionary*)serialize { …
diegoreymendez
  • 1,997
  • 18
  • 20
5
votes
6 answers

How to use a private method in Java

I am given a class that has a private method say setCoors(int x, int y). The constructor of that class has the setCoors in it too. In a different class, I want to have a method setLocation which calls setCoors. Is this possible? New Question: If I…
Dan
  • 8,263
  • 16
  • 51
  • 53
5
votes
3 answers

How to distribute an app for internal use only amongst employees

The company I work for is coming near to completion of app for internal use only amongst employees. There are some things that from my research I am not clear on and would like to hear from people who have deployed apps using this method. What s the…
5
votes
3 answers

How to call private functions of a class from outside the class in Kotlin

I want to call a private functions of class SomeClass from outside of this class: class SomeClass { private fun somePrivateFunction() { //... } private fun somePrivateFunctionWithParams(text: String) { //... …
Sergio
  • 27,326
  • 8
  • 128
  • 149
5
votes
1 answer

Rails testing controller private method with params

I have a private method in a controller private def body_builder review_queue = ReviewQueueApplication.where(id: params[:review_queue_id]).first ... ... end I would like to test just the body_builder method, it is a method buidling…
legendary_rob
  • 12,792
  • 11
  • 56
  • 102
5
votes
2 answers

How to create private methods that can be redefined in subclasses in Dart?

Whenever I define a private method like this: class ParentClass { sayHi() { _initiateGreeting(); } _initiateGreeting() { print("I'm a parent class"); } } It is not possible to redefine it in a subclass: class ChildClass extends ParentClass { …
orion3
  • 9,797
  • 14
  • 67
  • 93
5
votes
2 answers

PHP class private property and method

Noticed something about PHP's classes and I don't know if it's a bug or why it works, this is the code: echoProp(); } private…
Emi
  • 1,018
  • 9
  • 13
5
votes
3 answers

Asserting Exceptions for Private Methods

I am unit-testing private methods in C# using NUnit. For example, my method (if public) is expected to throw an ArgumentNullException. I can assert that the method throws an ArgumentNullException like so: Assert.Throws(() =>…
user5398447
4
votes
5 answers

How to write a "truly" private method in C#?

In fact, private methods are implemented in C# that can still be searched with Reflection. What I am going to do is to write public string Encrypt(string data) and private string Decrypt(string cipher) methods to perform encryption and…
Alex Yeung
  • 2,495
  • 7
  • 31
  • 48
4
votes
1 answer

Why can child override and access its parent private method?

I'm used to put method as protected in my PHP classes. But playing with private I'm starting to have doubts. I know that it might be a duplicate but I can't find clarity from the SO-answers I've read. Checked the documentation and SO answers but…
Kamafeather
  • 8,663
  • 14
  • 69
  • 99
4
votes
4 answers

Unit testing as applied to private methods

I'm currently trying to create some classes to do some Fourier Transformations. I'm trying to do it by creating some unit tests first, then build the basic functionality. The problem with this is, is that well, I can write one test to see if the…
Timo Willemsen
  • 8,717
  • 9
  • 51
  • 82
4
votes
2 answers

How python resolves private(double underscore) methods inside a class?

Consider the following class class Foo(object): @staticmethod def __is(): print('__is') def m(self): Foo.__is() # executes Foo.__is() # fails because of mangling print(Foo.__dict__.keys()) Foo.__is() when it is…
Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
4
votes
1 answer

Why is my top-level method public (as opposed to private) on all classes when I declare it in IRB?

I'm currently reading "The Well-Grounded Rubyist", and on page 196 I see the following: Suppose you define a method at the top level: def talk puts "Hello" end .... A method that you define at the top level is stored as a private instance…
Richie Thomas
  • 3,073
  • 4
  • 32
  • 55
4
votes
1 answer

org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke private void init()

For some reason, the following code is not working, and I do not understand why. My current, and quite hand-wavy, belief from fussing around with several slight variations is that because the bean is being created before there is an ExternalContext…
D. Law.
  • 234
  • 1
  • 3
  • 8
4
votes
1 answer

Methodhandle private method called using findVirtual

Java doc of MethodHandle says that private method should invoke via findSpecial.But in the following example I am able to invoke it via findVirtual. Could somebody please explain what am I missing here? import java.lang.invoke.MethodHandles; import…
shilrast
  • 41
  • 2