How to alias load_data?

I'm not sure what class or module the load_data command belongs to.  I want to alias it so I can do some extra processing whenever a database file or a map is loaded.  Does anyone know what the correct syntax would be (or how I would find where load_data "lives")?
Not sure if this is what you are after, but in rpg_managers.js there is the code for the DataManager object that includes functions for loading different data, including map data.


Nevermind - my bad, wrong RPGmaker :X
Yeah, Ace 🙂


Ah, it's a built-in function, like rgss_main:

load_data(filename)



Loads the data file indicated by filename and restores the object.



$data_actors = load_data("Data/Actors.rvdata2")

This function is essentially the same as:

Code:
File.open(filename, "rb") { |f|
  obj = Marshal.load(f)
}


However, it differs in that it can load files from within encrypted archives.





So that shows me where it is, but I'm still unsure how to alias it ...


Edit: think I've got it:

Code:
alias shaz_load_data load_data

def load_data(file)
  p 'loading file ' + file
  shaz_load_data(file)
  # do stuff here
end



Edit2: And now that I've got it, I don't think I can use it for the desired purpose, as database objects are arrays, and a map isn't.  So back to plan 1 (2 separate methods), and at least I learned something new today.
Probably not helpful anymore, but for the sake of completion:


load_data is a private instance method from the Kernel module (it should therefore show up when you use Kernel.private_instance_methods(false)).


Good luck with your project.
Edit2: And now that I've got it, I don't think I can use it for the desired purpose, as database objects are arrays, and a map isn't.  So back to plan 1 (2 separate methods), and at least I learned something new today.



And that's why we got:


object.is_a?(Array)


Which should let you do what you want, I guess.


You can also check the file name itself to know ahead what is loaded exactly. A map file always has "MapNNN" in it's name, the data file for weapons is always named "Weapons.rvdata2", and so on. 
Thanks guys.  

Original thread: https://forums.rpgmakerweb.com/threads/how-to-alias-load_data.60183/