Mitsukiの魔法実験室

Mitsuki's Magic Laboratory
Since 2002.09.14

Information

現時点で以下のSNSアカウントを運用しています。

Fedibird: @mitsuki64@fedibird.com
Mastodon系。現在のメインアカウント。
Bluesky: @mitsuki64.fedibird.com.ap.brid.gy
Bluesky系。@mitsuki64@fedibird.comへのブリッジ。
notestock: mitsuki64
Mastodon等のログを蓄積・検索できるサービス。FedibirdとVivaldi socialのアカウントを登録中。
Misskey.io: @mitsuki64@misskey.io
Misskey系。RN/リアクションのみ。
Vivaldi social: @mitsuki64@vivaldi.net
Mastodon系。メインをFedibirdへ移動したため、ログ参照のみ。
Twitter: @mitsuki
プライベートモード、ログ参照のみ。

load '~/.someconf'

Posted at 2007/07/30 19:28 in Ruby

 Ruby で設定ファイルを読み込む定番は Kernel.load だけど、なんとなく設定項目をローカル変数にしたら何も読み込まれなくて、きょとん。

~./someconf:
someconf = 'is in HOME'
p local_variables
p self
some.rb:
somerb = 'is in somewhere'
load '~/.someconf'
p local_variables
p self
実行結果:
/path/to/somewhere>ruby some.rb
["someconf"]
main
["somerb"]
main
/home>

 どうやら load 元と load 先ではスコープが違うらしい(load 先が別メソッド内にあるような感じ?)。self は共通なので、インスタンス変数にするのが正解なのかな(@someconf みたいに)。

Page 1/41: 1 2 3 4 5 6 7 8 9 [>] [>>]