1 2 3 4 5 6 | irb(main):001:0> "This is a string.".class => String irb(main):002:0> 'This is also a string.'.class => String irb(main):003:0> String.new('This is yet another string.').class => String |
1 2 3 4 5 6 7 | irb(main):004:0> puts 'Use \n to specify a new line in Ruby.' Use \n to specify a new line in Ruby. => nil irb(main):005:0> puts "A \\n causes a line break \n like this." A \n will cause a line break like this. => nil |
1 2 3 4 5 | irb(main):006:0> name = "Elvis" => "Elvis" irb(main):007:0> puts "Your name is #{name}" Your name is Elvis => nil |
1 2 3 4 5 6 7 8 | irb(main):008:0> template = 'Your name is #{name}' => "Your name is \#{name}" irb(main):009:0> name = gets Elvis => "Elvis\n" irb(main):011:0> puts eval('"' + template + '"') Your name is Elvis => nil |
1 2 3 4 | <% 4.times do |i|%> <h1>This code is inside the loop.</h1> <p>This line is pass number <%= i %> through the loop.</p> <% end %> |
1 2 3 4 5 6 7 8 9 10 11 12 13 | > erb test.rhtml <h1>This code is inside the loop.</h1> <p>This line is pass number 0 through the loop.</p> <h1>This code is inside the loop.</h1> <p>This line is pass number 1 through the loop.</p> <h1>This code is inside the loop.</h1> <p>This line is pass number 2 through the loop.</p> <h1>This code is inside the loop.</h1> <p>This line is pass number 3 through the loop.</p> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |