トップ 最新 追記


http://www.xrea.com/ http://www.value-domain.com/

ryuone日記

2004|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|
2008|02|06|07|12|
2009|01|03|04|05|08|09|10|
2010|03|04|05|06|07|08|09|

2010-04-07

_ [Ruby] instance_evalの使い方

Rackのサンプルアプリを作ってて、Rackのサンプルを眺めてたんだけど、

useってどこで宣言してあるんだ?って悩んだ。

よくよくみてみると、newした時のinitializeで、instance_evalをしてbuilder内のインスタンスメソッドにアクセスできるような作りになっていた。

rack/builder.rbのinstance_evalの使い方の簡単な例は以下の通り。

class MyClass
  attr_reader :tnum
  @@totalnum = 0
  def initialize(cnt, &block)
    @tnum = 0;
    cnt.times{
      instance_eval(&block) if block_given?
    }
  end
 
  def add (num)
    @@totalnum += num
    @tnum += num
  end
  class << self
    def total
      @@totalnum
    end
  end
end
 
o = MyClass.new(3) {
  add 10
}
puts o.tnum
puts MyClass.total
puts "-----------"
o = MyClass.new(3) {
  add 10
}
puts o.tnum
puts MyClass.total

この結果は、

30
30
-----------
30
60

になる。


2010-04-08

_ [Ruby] Redmineの環境を構築した。(Redmine on Passenger)

会社のマシン(CentOS release 4.4 [2.6.9-42.0.10.EL])に入れてみようと思い、 いろいろ調べながら以下の環境で作れた。

 ■インストールしたモジュール
1) ruby 1.8.7 (2010-01-10 patchlevel 249)
2) rubygems-1.3.6
	actionmailer (2.3.5)
	actionpack (2.3.5)
	activerecord (2.3.5)
	activeresource (2.3.5)
	activesupport (2.3.5)
	fastthread (1.0.7)
	passenger (2.2.11)
	rack (1.0.1)
	rails (2.3.5)
	rake (0.8.7)
	sqlite3-ruby (1.2.5)
 
            sudo gem1.8 install rails
            sudo gem1.8 install sqlite3-ruby -- --with-opt-dir=/opt/app/sqlite3
            sudo gem1.8 install passenger
 
3) httpd-2.2.15
4) redmine-0.9.3
5) sqlite-3.6.23
 ■インストール先
1) /opt/app/ruby1.8
     ./configure --prefix=/opt/app/ruby1.8 --program-suffix=1.8
3) /opt/app/apache2
     ./configure --prefix=/opt/app/apache2 --with-included-apr --enable-rewrite --with-mpm=prefork
4) /opt/app/redmine
5) /opt/app/sqlite3
     ./configure --prefix=/opt/app/sqlite3 --disable-tcl
 ■Redmineの設定

SQLite3を使用するので

production:
  adapter: sqlite3
  database: db/redmine.db
  timeout: 5000
cd /opt/app/redmine
/opt/app/ruby1.8/bin/rake config/initializers/session_store.rb
/opt/app/ruby1.8/bin/rake db:migrate RAILS_ENV=production
/opt/app/ruby1.8/bin/rake redmine:load_default_data RAILS_ENV=production
 ■メールの設定はパス

これまでの設定で問題無いか、Redmineを起動してみる。

/opt/app/ruby1.8/bin/ruby1.8 script/server -e production
 ■Passengerの設定
/opt/app/ruby1.8/bin/passenger-install-apache2-module

を起動の前に、

export APXS2=/opt/app/apache2/bin/apxs
export PATH=/opt/app/apache2/bin:$PATH

を行う。 設定が出来たら、

/opt/app/ruby1.8/bin/passenger-install-apache2-module

を実行。

あとは、LoadModuleやら、VirtualHostの設定内容が表示されるので、それをコピーしておき、

httpd.confに記述するのみ。

extra/httpd-passenger-1.8.confを作成し、その中に、

NameVirtualHost *:9090
 
LoadModule passenger_module /opt/app/ruby1.8/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
PassengerRoot /opt/app/ruby1.8/lib/ruby/gems/1.8/gems/passenger-2.2.11
PassengerRuby /opt/app/ruby1.8/bin/ruby1.8
 
<VirtualHost *:9090>
   ServerName centos.local
   DocumentRoot /opt/app/redmine/public
   <Directory /opt/app/redmine/public>
      AllowOverride all
      Options -MultiViews
      allow from all
   </Directory>
</VirtualHost>

を設定、80番portが使用されていた為、httpd.confのPortを9090に変更

httpd.confの最後に、

Include conf/extra/httpd-passenger-1.8.conf

を追加

これで、あとは/opt/app/apache2/bin/apachectl startでApache2が起動するのみ。

一応、これで環境出来た。不備があれば連絡をください。


あと

gitのインストール場所が/usr/local/bin/git等に無い場合は、

/opt/app/redmine/lib/redmine/scm/adapters/git_adapter.rb

GIT_BIN = "git"

を変更する必要があるかも。


2010-04-20

_ [English] 述語動詞と準動詞を勉強

【述語動詞】
動詞(verb)の働きだけをしている動詞。
【準動詞】
動詞(verb)の働き以外に名詞(noun)または形容詞(adjective)または副詞(adverb)の働きを兼ねている動詞。

2010-04-25

_ [etc] torneを購入

出荷は4月30日予定なので、G.W.中には設定できるかな。


2010-04-27

_ [Memo] ATOK

Synegyを使って、Windows側のATOKの日本語入力をON/OFFを切り替える方法。

1)ATOKプロパティを開いて、「キーカスタマイズ」ボタンを選択。

2010426232515

2)「キーを検索」ボタンをクリック

2010426232533

3) SHIFT+CTRL+SPACEを日本語ON/OFFに割り当てる。

2010426232600

2010426232620

5) スタイル名を入力して終了

2010426232635

以上。