Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Apidcloud on August 21, 2011, 01:32:59 pm

Title: [Resolved] Any good way to go around the private methods?
Post by: Apidcloud on August 21, 2011, 01:32:59 pm
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
Title: Re: Any good way to go around the private methods?
Post by: Blizzard on August 21, 2011, 01:41:12 pm
class Bitmap
  def get_local_variables
    return self.local_variables
  end
end
Title: Re: Any good way to go around the private methods?
Post by: Apidcloud on August 21, 2011, 01:51:50 pm
Same thing shows up.

This is so strange lol
Local_variables shouldn't be inaccessible, instance_variables do -.-
Title: Re: Any good way to go around the private methods?
Post by: Blizzard on August 21, 2011, 01:59:11 pm
That's because instance_variables isn't private. That's just the way it is.
Title: Re: Any good way to go around the private methods?
Post by: Apidcloud on August 21, 2011, 02:01:31 pm
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

Title: Re: Any good way to go around the private methods?
Post by: Blizzard on August 21, 2011, 02:18:35 pm
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.
Title: Re: Any good way to go around the private methods?
Post by: Apidcloud on August 21, 2011, 02:21:15 pm
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?  :^_^':
Title: Re: Any good way to go around the private methods?
Post by: Blizzard on August 21, 2011, 02:24:56 pm
Yeah, you should. xD
Title: Re: Any good way to go around the private methods?
Post by: ForeverZer0 on August 21, 2011, 02:49:19 pm
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)
Title: Re: Any good way to go around the private methods?
Post by: 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.
Title: Re: Any good way to go around the private methods?
Post by: Apidcloud on August 21, 2011, 04:39:59 pm
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
Title: Re: Any good way to go around the private methods?
Post by: Blizzard on August 21, 2011, 06:00:13 pm
Yeah, [Resolved] is fine.