0

I was reading something else posted by a user on here explaining how yield statements work in Ruby. Part of the code he was using was :

print_list( [1,2,3], 23 ) { |n| "<#{n}>"}

what do the < > mean inside the string? It's such a simple question but I haven't been able to find out the answer to it.

user2864740
  • 60,010
  • 15
  • 145
  • 220
user3619165
  • 380
  • 1
  • 2
  • 13
  • 4
    they have no meaning. They're just characters in the string. – sevenseacat May 09 '14 at 05:53
  • It cannot be told out of context. – sawa May 09 '14 at 05:57
  • 3
    This question appears to be off-topic because it is about a simple misunderstanding (false assumption) and is highly unlikely to be helpful to future readers. – Darshan Rivka Whittle May 09 '14 at 06:15
  • You are referring to http://www.codecademy.com/forum_questions/51c72e759c4e9d410501df42, right? It's about *formatting* the output, in this case: enclosing the numbers in angle brackets / chevrons. – Stefan May 09 '14 at 06:57

2 Answers2

5

In a string literal neither < nor > have any implied meaning - although such might have meaning in the output or use of the resulting string.

Only escape sequences and # (in interpolated literals) have intrinsic meaning.

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • 1
    One more point in case of *interpolation*, `@`,`@@` and `$` are also have intrinsic meanings.. – Arup Rakshit May 09 '14 at 07:42
  • @ArupRakshit It's definitely good to keep in mind, although I think that simply means [that the braces can be omitted](http://stackoverflow.com/questions/10091156/why-does-string-interpolation-work-in-ruby-when-there-are-no-curly-braces) - i.e. in conjunction with `#` only. – user2864740 May 09 '14 at 07:46
  • Yes... right! That I thought I should mention in my previous comment. :-) – Arup Rakshit May 09 '14 at 07:54
0

These characters are just a part of string.

And any character which lies inside #{ } will be evaluated, which is also referred to Interpolation

cvibha
  • 693
  • 5
  • 9