[ruby-list:39061] block method in #{}

From: thitoshi@... (TAKAHASHI Hitoshi)
Date: 2004-01-22 06:06:38 UTC
List: ruby-list #39061
  高橋と申します。

  文字列中の #{} の中でブロック付きメソッドを呼ぶと、
Ruby 1.6 では問題ないのに 1.8 では syntax error に
なってしまいます。

% ruby1.6 -ve 'puts "#{2.times do |i| p i end}"'
ruby 1.6.8 (2003-07-09) [i386-linux]
0
1
2
% ruby1.8 -ve 'puts "#{2.times do |i| p i end}"'
ruby 1.8.1 (2004-01-20) [i386-linux]
-e:1: syntax error
puts "#{2.times do |i| p i end}"
                  ^
-e:1: syntax error
puts "#{2.times do |i| p i end}"
                          ^
-e:1: unterminated string meets end of file
% 

do/end ではなくて {} で囲むと 1.8 でもエラーになりません。

% ruby1.8 -ve 'puts "#{2.times { |i| p i }}"'
ruby 1.8.1 (2004-01-20) [i386-linux]
0
1
2
% 

バグでしょうか?

-------------------------------------------------------------------
                       TAKAHASHI Hitoshi
         Institute of Particle and Nuclear Studies, KEK
            E-mail: hitoshi.takahashi@kek.jp
                    thitoshi@post.kek.jp
                    thitoshi@nh.scphys.kyoto-u.ac.jp
   URL: http://www-ps.kek.jp/thitoshi/index.html
        http://www-nh.scphys.kyoto-u.ac.jp/~thitoshi/member.html
-------------------------------------------------------------------

In This Thread

Prev Next