Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the origin of `%i` notation? [closed]

Tags:

syntax

ruby

Ruby has classically supported the following literals:

%q[quack quack] #=> "quack quack"
%r[quack quack] #=> /quack quack/
%w[quack quack] #=> ["quack", "quack"]
%x[echo quack quack] #=> "quack quack\n"

My understanding of the origin of those are as follows:

  • %q[] is for quotes
  • %r[] is for regex
  • %w[] is for words
  • %x[] is for execute

Ruby 2.0 introduced the %i notation:

%i[quack quack] #=> [:quack, :quack]

Why i?

like image 926
fny Avatar asked Jun 27 '13 23:06

fny


1 Answers

It's probably a reference to the String#intern method used to get a symbol from a string.

"foo".intern #=> :foo
like image 84
Alex Wayne Avatar answered Sep 22 '22 15:09

Alex Wayne