<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/xml.xsl" type="text/xsl"?><feed xmlns="http://www.w3.org/2005/Atom">
  <title>nulog, NULL::something : out of the headphone &gt; 2004 &gt; September &gt; 05</title>
  <link href="http://lowreal.net/logs/2004/09/05"/>
  <icon>http://lowreal.net/img/banner.png</icon>
  <link rel="self" type="application/atom+xml" href="http://lowreal.net/logs/2004/09/05.atom"/>
  <link rel="alternate" type="application/xhtml+xml" href="http://lowreal.net/logs/2004/09/05.xhtml"/>
  <updated>2004-09-05T19:00:26+09:00</updated>
  <author>
    <name>cho45(砂糖)</name>
  </author>
  <id>http://lowreal.net/2004/09/05</id>
  <entry>
    <title>ひたすら面白くない日々と、ひたすら面白いことを考える日々</title>
    <link rel="alternate" type="text/html" href="http://lowreal.net/logs/2004/09/05/1.html"/>
    <link rel="alternate" type="application/xml+xhtml" href="http://lowreal.net/logs/2004/09/05/1.xhtml"/>
    <updated>2004-09-05T04:26:53+09:00</updated>
    <published>2004-09-05T04:26:53+09:00</published>
    <id>http://lowreal.net/2004/09/05/1</id>
    <category term="life"/>
    <content type="xhtml" xml:base="http://lowreal.net/">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>土曜日は朝から「なんで土曜日に学校なんかいかなきゃいけないんだ。しかもあの糞学校に」と考え、日曜日は「あぁまた明日から糞学校か」と凹み、平日は淡々と脳みそがやせていく日々である。</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>○×＋運</title>
    <link rel="alternate" type="text/html" href="http://lowreal.net/logs/2004/09/05/2.html"/>
    <link rel="alternate" type="application/xml+xhtml" href="http://lowreal.net/logs/2004/09/05/2.xhtml"/>
    <updated>2004-09-05T04:36:13+09:00</updated>
    <published>2004-09-05T04:36:13+09:00</published>
    <id>http://lowreal.net/2004/09/05/2</id>
    <category term="life"/>
    <content type="xhtml" xml:base="http://lowreal.net/">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>どこの大学に入ってもインチキ野郎が大量にいるんじゃないかと思うこの頃。周りに誰がいるかとかそういうのって全部運じゃないか……</p>
        <p>じゃあどこにインチキ野郎がいないかって言ったら、いないとこなんてないんじゃないかと思うこの頃。どれぐらいいるんだろう。</p>
        <p>関係ないけど、妙に気取ってる人が苦手だ。すごいくだらないんだけど、高校生なら「高校生らしく」するべきで、たかが粋がってるだけの高校生が「飲みいこうぜ、のみ」とか言ってるのはなんか胡散臭いって思うような。別に粋がってるやつだけじゃなくて、言葉（文字）遣いが気取ってたり、格がないのに一人称が「私」だったりするとなんかめげる。</p>
        <p>人のこと言ってるんじゃねぇよ。　さて、自分で判断できないことはどうやって直せばいいだろう。</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>php ?</title>
    <link rel="alternate" type="text/html" href="http://lowreal.net/logs/2004/09/05/3.html"/>
    <link rel="alternate" type="application/xml+xhtml" href="http://lowreal.net/logs/2004/09/05/3.xhtml"/>
    <updated>2004-09-05T12:44:32+09:00</updated>
    <published>2004-09-05T12:44:32+09:00</published>
    <id>http://lowreal.net/2004/09/05/3</id>
    <category term="prog"/>
    <content type="xhtml" xml:base="http://lowreal.net/">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>domxml は <abbr title="PHP: Hypertext Preprocessor">PHP</abbr>5 で使えなくて、DOMDocument とか XSL は 4 では使えないってか。ローカルで xslt_process のロードするときのパスがオカシイのでいちいち fopen する必要ありまくりですか。めんどくさい。</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Ruby プラグインっぽいもん</title>
    <link rel="alternate" type="text/html" href="http://lowreal.net/logs/2004/09/05/4.html"/>
    <link rel="alternate" type="application/xml+xhtml" href="http://lowreal.net/logs/2004/09/05/4.xhtml"/>
    <updated>2004-09-05T14:26:07+09:00</updated>
    <published>2004-09-05T14:26:07+09:00</published>
    <id>http://lowreal.net/2004/09/05/4</id>
    <category term="prog"/>
    <content type="xhtml" xml:base="http://lowreal.net/">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>別ファイルに定義されたクラスを動的に読み直したいのだけど、どうやっていいやら。単に <code class="Ruby">eval</code> とかやると<q>同じクラス名はもう使ってるぜ？</q>って警告されるわけだし、<code class="Ruby">Class::new do ... end</code> は違うくさいし、<code class="Ruby">remove_const</code> はメソッド内から呼べない<span class="fn"><code class="Ruby">self.remove_const</code> がないよって怒られるわけだから、他に方法があるのかもしれない？ <ins datetime="2004-09-05T17:17:46+09:00"><code class="Ruby">定義したクラス名.class_eval("remove_const(:CONST)")</code>ってやればいいらしい（<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/38594">[ruby-list:38594] Re: cgi.rbのremove_const</a>）。これで上手くいくかどうか実装してみよう。</ins></span>し。</p>
        <p>プラグインみたいな。ずっと動きっぱなしのプログラムで、ある一部分だけソースからもう一度読み直してやりたい。</p>
        <p># <abbr>ML</abbr> の過去ログで面白いのハケン <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/27327">[ruby-list:27327] Haiku</a>. こういうの好き</p>
        <ins datetime="2004-09-05T17:27:13+09:00">
          <pre class="Ruby">
class PluginManager

    def initialize
        @plugins = {}
    end

    def class_name(filename)
        File::basename(filename, ".rb").capitalize
    end

    def load(filename)
        class_name = class_name(filename)
        eval(open(filename) {|f| f.read }, binding)
        # インスタンス作成して @plugin に突っ込む。
        eval("@plugins[class_name] = #{class_name}::new")
    end

    def unload(filename)
        class_name = class_name(filename)
        PluginManager.class_eval("remove_const(:#{class_name})")
        @plugins.delete(class_name)
    end

    def each
        @plugins.each do |k,v|
            yield k, v
        end
    end

end

pm = PluginManager::new
pm.load("foo.rb")
f = PluginManager::Foo::new
pm.unload("foo.rb")
f = PluginManager::Foo::new # =&gt; uninitialized constant PluginManager::Foo (NameError)

=begin
# foo.rb
class Foo
end
=end</pre>
          <p>みたいな感じかなぁ……もっとスマートにできるような気がする。しかもコレだと PluginManager の外からロードしたクラスにアクセスできる（丁度上の <var>f</var> のように ）んだよね。もう一個 Plugin クラスとか作ってその中にロードしたクラスのインスタンス突っ込んでやろうか。</p>
        </ins>
      </div>
    </content>
  </entry>
  <entry>
    <title>Ruby PluginManager と命名規則</title>
    <link rel="alternate" type="text/html" href="http://lowreal.net/logs/2004/09/05/5.html"/>
    <link rel="alternate" type="application/xml+xhtml" href="http://lowreal.net/logs/2004/09/05/5.xhtml"/>
    <updated>2004-09-05T19:00:26+09:00</updated>
    <published>2004-09-05T19:00:26+09:00</published>
    <id>http://lowreal.net/2004/09/05/5</id>
    <category term="prog"/>
    <content type="xhtml" xml:base="http://lowreal.net/">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>外側からアクセスできるのはそんな大きな問題にはならないような気がするので、このまま実装してこう。まぁクラスオブジェクトを適当に突っ込んだらすぐに <code class="Ruby">remove_const</code> すればいいような気がしないでもない。この辺考えよう……</p>
        <p>前回ロード時のファイル日時と比べて更新されてたらリロードするメソッドとかとか。</p>
        <p>ちなみに結構命名規則がいいかげんな感じで統一してたりする。クラス名とかモジュール名は単語先頭を大文字にする（どっちにしろクラス名先頭は大文字だし）形で、メソッド名とか変数名はアンダースコアで単語つなぐ、ってのを基本として適当に単語作ったり略したり。</p>
        <dl title="俺感性の命名">
          <dt>foo_bar</dt>
          <dd>普通</dd>
          <dt>FooBar</dt>
          <dd>WinAPI とか、C とかっぽい気がする。読み難いし書きづらいし間違いやすい。</dd>
          <dt>FOO_BAR</dt>
          <dd>定数</dd>
          <dt>fooBar</dt>
          <dd>なんかダサい</dd>
          <dt>Foo_Bar</dt>
          <dt>Foo_bar</dt>
          <dd>あんまり見かけない</dd>
          <dd>激しくダサい</dd>
        </dl>
        <p>どうでもいい話だ。でも Ruby のメソッド名に大文字が混ざってると違和感！　Javascript だといろいろ混ざったりとか……キタネ</p>
        <ins datetime="2004-09-05T19:22:13+09:00">
          <p>ていうか、インスタンス作ったらすぐに remove_const やってもいいのかな。</p>
        </ins>
      </div>
    </content>
  </entry>
</feed>
