What does the “$” character mean in Ruby?

前端 未结 5 1647
深忆病人
深忆病人 2020-12-08 01:40

Been playing with Ruby on Rails for awhile and decided to take a look through the actual source. Grabbed the repo from GitHub and started looking around. Came across some co

5条回答
  •  猫巷女王i
    2020-12-08 02:36

    To quote the Ruby Forum:

    ruby comes with a set of predefined variables

    $: = default search path (array of paths)
    __FILE__ = current sourcefile
    

    if i get it right (not 100% sure) this adds the lib path to this array of search paths by going over the current file. which is not exactly the best way, i would simply start with RAILS_ROOT (at least for a rails project)

提交回复
热议问题