Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Syntax Error on Ruby Blocks

Understanding Syntax Error on Ruby Blocks

Tetsuya Kaneko

April 16, 2019
Tweet

More Decks by Tetsuya Kaneko

Other Decks in Programming

Transcript

  1. Ruby Blocks ʹ͓͚Δ Syntax Error ͷṖΛ௥͏ 
 2019.4.16 ࣾ಺LTେձ #1

    
 @tetsuya
  2. ໰୊

  3. ͜ͷίʔυ͸ಈ͘Ͱ͠ΐ͏͔ʁ 1.upto(2) {|i| p i }

  4. ಈ͘ $ ruby -e '1.upto(2) {|i| p i } '

    1 2
  5. ͡Ό͋ͬͪ͜͸ʁ 1.upto 2 {|i| p i }

  6. ౴͑

  7. όʔδϣϯʹΑΔ

  8. Ruby 1.9.0-4 (ಈ͘) $ ruby -ve '1.upto 2 {|i| p

    i} ' ruby 1.9.0 (2008-08-26 revision 18849) [i386-darwin18.2.0 ] 1 2
  9. Ruby 2.3.3 (ಈ͔ͳ͍) $ ruby -ve '1.upto 2 {|i| p

    i} ' ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin18 ] -e:1: syntax error, unexpected '{', expecting end-of-inpu t 1.upto 2 {|i| p i}
  10. Ruby 2.4.0 (ಈ͘) $ ruby -ve '1.upto 2 {|i| p

    i} ' ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin18 ] 1 2
  11. Ruby 2.4.1 (ಈ͘) $ ruby -ve '1.upto 2 {|i| p

    i} ' ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin18 ] 1 2
  12. Ruby 2.4.2 (ಈ͔ͳ͍) $ ruby -ve '1.upto 2 {|i| p

    i} ' ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin18 ] -e:1: syntax error, unexpected '{', expecting end-of-inpu t 1.upto 2 {|i| p i}
  13. ͳ͔ͥ

  14. ྺ࢙ΛḪΔ͜ͱ10೥ • ΋ͱ͸1.9Ͱ࢓༷มߋͱͯ͠௥Ճ͞ΕɺΑΓ਌੾ʹϒϩοΫΛղ ऍ͢ΔΑ͏ͳ΋ͷͩͬͨ • ʮϓϩάϥϚ͸ a {|i| ...} ͸ϝιουݺͼग़͠ͱͯ͠ղऍ͢Δ͕ɺ

    2 {|i| …} ͸ϝιουݺͼग़͠ͱ͸ղऍ͠ͳ͍͸ͣͩʯ • ʮϦςϥϧͰ͋Δ͔ม਺Ͱ͋Δ͔ͰৼΔ෣͍͕ҟͳΔ͜ͱ͸ɺࠞ ཚΛট͘Մೳੑ͕͋Δʯ Bug #505: 1.upto 2 {|i| p i } - Ruby trunk - Ruby Issue Tracking System
  15. ٞ࿦ͷ຤ * parse.y (yylex): "1.upto 2 {|i| p i }"

    should be syntax error. · ruby/ruby@05edaf5
  16. ͦͷޙ΋ಈ͍ͨΓಈ͔ͳ͔ͬͨΓ • Bug #13547: [].delete 1 { 'NG' } -

    Ruby trunk - Ruby Issue Tracking System • Bug #14023: SyntaxError on array argument and block - Ruby trunk - Ruby Issue Tracking System
  17. ݁࿦ • ɹɹɹɹɹɹɹɹɹ͸ Syntax error ͕ͩɺRuby ͷόʔδϣϯ ʹΑͬͯ͸ಈ͍ͯ͠·͏ 1.upto 2

    {|i| p i }