Search code examples
rubymetasploit

How ruby find module


Say you have the code below.

require 'msf/core'

Class xxx

  ...

end

I have some questions about it .

I know if there is not a file in the require then should be a module.

  1. Does msf/core means search a core.rb in the folder msf under a certain of path of $:?
  2. msf/core seems like a path .Any definition syntax for it ?

Solution

  • I know if there is not a file in the require then should be a module.

    As I know require has nothing to do with module names. It always takes filenames.

    So how ruby find the module ?

    It doesn't find. It loads a file and its content.

    msf/core seems like a path .Any definition syntax for it ?

    Yes it is a path to a required file relative to $LOAD_PATH ($:). File extension may be omitted. In this case this is msf/core.rb file in your LOAD_PATH.

    BTW this variable is Array which can be modified with custom paths:

    $:.unshift('/usr/share/my_rb_files/')
    

    What is the difference between module and class?

    In this case there is no difference.


    I think RubyDoc has enough information about how it works.