Ray's playground

 

Recipe 1.2 Substituting variables into strings

1 number = 5
2 puts "The number is #{number}."
3 puts "The number after #{number} is #{number.next}."
4 puts "#{number}" == '5'
output: The number is 5.
            The number after 5 is 6.

            true

1 puts %{Here is #{class InstantClass
2        def bar
3           "some text"
4         end
5      end
6      InstantClass.new.bar
7     }.}

output: Here is some text.

To avoid triggering string interpolation, escape the hash characters or put the string in single quotes.
      "\#{foo}"      # => "\#{foo}"
       '#{foo}'      # => "\#{foo}"

posted on 2009-09-18 23:12  Ray Z  阅读(124)  评论(0编辑  收藏  举报

导航