11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rubyのハッシュ形式で記述された設定ファイルを読み込む

Posted at

概要

設定ファイルをRubyのハッシュ形式で記述し、読み込んで使う方法。

方法

以下のような設定ファイルがあるとする。

config.rb
{
  :username => 'hogehoge',
  :password => 'hugahuga',
}

これを読み込むには以下のようなコードを記述する。

sample.rb
config = eval File.read 'config.rb'
p config

参考

[Ruby] ユーザの設定ファイルの読み込み(ハッシュ編)
http://d.hatena.ne.jp/kitokitoki/20110601/p1

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?