タイトルのとおり。ずっと悩んでしまった。
読み込まれる側のアクションで、render :layout => false するべきらしい。
http://rails.techno-weenie.net/question/2006/1/14/render_component_infinite_loop
http://jp.rubyist.net/magazine/?0015-EditorsNote
そのまんまの書き方しかできなかった。
OPERATORS = %w(+ - * /)
def rpolish2tree(expr)
stack = []
expr.each do |t|
if OPERATORS.include?(t)
rhs = stack.pop
lhs = stack.pop
stack.push([t, lhs, rhs])
else
stack.push(t)
end
end
stack[0]
end
def tree2polish(tree, result)
if tree.is_a?(Array)
op, lhs, rhs = tree
result.push(op)
tree2polish(lhs, result)
tree2polish(rhs, result)
else
result.push(tree)
end
result
end
def polish2tree(expr)
stack = []
expr.each do |t|
stack.push(t)
while stack.size >= 3 && OPERATORS.include?(stack[-3]) && !OPERATORS.include?(stack[-2]) && !OPERATORS.include?(stack[-1])
rhs = stack.pop
lhs = stack.pop
op = stack.pop
stack.push([op, lhs, rhs])
end
end
stack[0]
end
def tree2rpolish(tree, result)
if tree.is_a?(Array)
op, lhs, rhs = tree
tree2rpolish(lhs, result)
tree2rpolish(rhs, result)
result.push(op)
else
result.push(tree)
end
result
end
rpolish = %w(1 2 2 / + 3 4 5 * + -)
#p rpolish2tree(rpolish)
p tree2polish(rpolish2tree(rpolish), [])
polish = %w(- + 1 / 2 2 + 3 * 4 5)
#p polish2tree(polish)
p tree2rpolish(polish2tree(polish), [])
ふと思いだしたのですが、駐車禁止の標識は `NO' だから斜線は左上から右下、と説明してある本がありました。 「意味付けを伴なうと忘れないでしょ」という主旨の文章だったと思います。 (すみません、本のタイトル忘れました。ミス(誤り)に関する本だったと思うんですが)
駐車禁止の標識に、本当にそのような意味付けがあるのかは確かめていません。
先日、新しいマシンに Rails 環境を作ってみたところ、 「colon will be obsoleted; use semicolon」という警告が大量に発生しました。
% ruby script/server /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:169: warning: colon will be obsoleted; use semicolon /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:170: warning: colon will be obsoleted; use semicolon /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:171: warning: colon will be obsoleted; use semicolon /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/json/encoders/core.rb:24: warning: colon will be obsoleted; use semicolon /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/json/encoders/core.rb:25: warning: colon will be obsoleted; use semicolon ...
調べてみると、これはつい最近 Ruby に入った変更が原因のようです。
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/parse.y.diff?r1=1.307.2.36;r2=1.307.2.37
--- ruby/parse.y 2006/06/20 16:41:08 1.307.2.36
+++ ruby/parse.y 2006/07/13 15:42:48 1.307.2.37
@@ -2,8 +2,8 @@
parse.y -
- $Author: nobu $
- $Date: 2006/06/20 16:41:08 $
+ $Author: matz $
+ $Date: 2006/07/13 15:42:48 $
created at: Fri May 28 18:02:42 JST 1993
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -1731,6 +1731,11 @@ primary_value : primary
then : term
| ':'
+ {
+ rb_warn("colon will be obsoleted; use semicolon");
+ value_expr($1);
+ $$ = $1;
+ }
| kTHEN
| term kTHEN
;
しかし、ここにコロンが書けたなんて初めて知りました。
% ruby -ve'if false: true end' ruby 1.8.5 (2006-07-14) [i686-linux] -e:1: warning: colon will be obsoleted; use semicolon
インスタンスからメソッドを取り出すには method を使う。
>> class C >> def initialize(n); @n = n; end >> def f; p @n; end >> end => nil >> c = C.new(5) => #<C:0x4afcd30 @n=5> >> m = c.method(:f) => #<Method: C#f> >> m.call 5 => nil
クラス(モジュール)から取り出す場合は instance_method を使う。 これはインスタンスを bind しなければ呼べない。
>> mm = C.instance_method(:f) => #<UnboundMethod: C#f> >> mm.bind(c) => #<Method: C#f> >> mm.bind(c).call 5 => nil
colon will be obsoleted; use semicolon の件を Rails の Trac に 登録しようとしたが、エラーが出て登録できなかった。 そのうちまた試してみよう。