Cross-platform means of getting user's home directory in Ruby?

前端 未结 5 385
情深已故
情深已故 2021-02-03 16:47

Java has the convienient System.getProperty(\"user.home\") to get the user\'s \"home\" directory in a platform-independent way. What\'s the equivalent in Ruby? I

5条回答
  •  盖世英雄少女心
    2021-02-03 17:45

    The File.expand_path method uses the Unix convention of treating the tilde (~) specially, so that ~ refers to the current user's home directory and ~foo refers to foo's home directory.

    I don't know if there's a better or more idiomatic way, but File.expand_path('~') should get you going.

提交回复
热议问题