[Resolved] Any good way to go around the private methods?

Started by Apidcloud, August 21, 2011, 01:32:59 pm

Previous topic - Next topic

Apidcloud

Hey there everyone, I'm trying to check the local_variables from Bitmap Class, but it's 'private'.
I printed Bitmap.local_variables
Here is what was raised lol:

Quote---------------------------
Project1
--------------------------
private method `local_variables' called for Bitmap:Class
---------------------------
OK  
---------------------------


Im trying to figure out the variable which initializes SDL.
I was almost sure it was an instance variable, but when I reversed the dll, it showed up a blank window only.
The local_variables one is the only that raises that private error.

As far as I know, the only way to access that kind of methods is inside of a method of the same class, although we can't use 'self.local_variables' to figure it out since it is a private method, not a protected one.

Any ideas?
Thanks
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

class Bitmap
  def get_local_variables
    return self.local_variables
  end
end
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

Same thing shows up.

This is so strange lol
Local_variables shouldn't be inaccessible, instance_variables do -.-
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

That's because instance_variables isn't private. That's just the way it is.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

August 21, 2011, 02:01:31 pm #4 Last Edit: August 21, 2011, 02:19:49 pm by Apidcloud
lol, but it doesn't return anything either -.- Besides, all the remake bitmap classes i've seen till now, uses an instance variable, so it can be used in all methods.


If only local_variables seems to be private...how can I get their names? :P

@Edit:
:facepalm:
F0 said Bitmap class is made in C, no damn way we'll be able to get the instance variable :P
Shall we forget about this? :P

Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

You don't have to. Local variables are all local within the scope of a method. It doesn't even make sense to use it outside of the class so just leave it.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

First of all, I wanted them to be used inside the same class :P

last post edit:
:facepalm:
F0 said Bitmap class is made in C, no damn way we'll be able to get the instance variable   :roll:
Shall we forget about this?  :^_^':
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ForeverZer0

I didn't say you couldn't get the instance variables, I said it is a bad and inefficient idea.

You can access private methods with Ruby's "send" method.  The thing is, there is absolutely nothing you can do wth them.  If you want to have a variable accessible, make an instance variable.

b = Bitmap.new(32, 32)
p b.send(:local_variables)
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

No, with the internal classes you actually can't get the instance_variables, because they haven't been exposed to Ruby.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

Well I was reading stuff about private and protected methods and variables, and it seems that blizz is right about what he said just now:
Quote from: Blizzard on August 21, 2011, 04:20:32 pm
No, with the internal classes you actually can't get the instance_variables, because they haven't been exposed to Ruby.


About local ones, F0 is absolutely right, and, as he said, I can't do anything with them, since they're local.
The instance_variables, are the ones that could be used, and my interest was in the one that initializes SDL...

Shall I had [Resolved] to the topic name? or any other thing? lol
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.