• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

ブロック引数を1つとるブロックつき関数を呼び出すときに

   1  create_table do |t|
   2    t.string :foo
   3  end

ブロック仮引数を省略した場合、暗黙のうちにブロック引数に対する instance_eval を挟むようにすると

   1  create_table do |t|
   2    t.instance_eval do
   3      string :foo
   4    end
   5  end

色々と綺麗にかけるようになる気がします。

   1  create_table do
   2    string :foo
   3  end

ついでに、省略されたブロック引数に $ とかでアクセスできると

   1  [1,2,3].map{to_s}.select{$>2}

みたいな事ができて楽しいかもです。 ついでに case の値もこんなふうに

   1  case price # <= この値を $ で参照したい
   2  when $ < 5; #...
   3  when $ < 10; #...
   4  end

参照できるといいな。

posted by Png genki on Wed 31 Aug 2011 at 07:52

前回(uninitialized constant MysqlCompat::MysqlResの対処法参照)はSnow Leopard でしたが、 今回はLionです。 OSのバージョンが変わるたびに問題が起こる気がします。 今回は、以下で回避できるようです。

   1  % install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /path/to/rubygems/gems/mysql-2.8.1/lib/mysql_api.bundle

See Also

posted by Png genki on Wed 31 Aug 2011 at 03:51
Contents
ブロック引数に対してinstance_evalするsyntax sugar
mysql gemがLionでuninitialized constant MysqlCompat::MysqlResを出す問題の回避法
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
瀧内元気: おお、チェックしてみます。thx! '11-12
overisland: Reeder for iPhone もこの UI を実装していますね。 '11-12
瀧内元気: その情報は見たのですが、以下のサイトによると、現在はまた必要になってるっぽいんですよね。 ... '11-12
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ