mruby/mruby — pull request #1043 by FUKUZAWA-Tadashi (2013-03-22 07:02:59+00:00)
Title: Proposal of ALCS : Array Literal of Closures and Strings

I propose a new feature ALCS: Array Literal of Closures and Strings.
(someone may have a better naming idea)
ALCS is literal for producing Array that contains String object and Proc object.

ALCS can:
* provide values of String and Proc.
* delay execution of expression expansion.

This is convenient for dynamical font handling such as changing color/size and animating message, as many games do.
I hope mruby is used by many game developers.

Could you visit my blog (in Japanese):
http://fukuzawa-tech.hatenablog.com/entry/2013/03/22/150043

1. ''%P'' works like ''%W''.
Expression expansion #{} become Proc object.
```
%W(foo asd#{1+2}qwe bar) # => ['foo', 'asd3qwe', 'bar']
%P(foo asd#{1+2}qwe bar) # => ['foo', 'asd', Proc.new{1+2}, 'qwe', 'bar']
```

2. ''%p'' works like ''%P''.
space char is not delimiter, is part of String.
'\n' is a delimiter, and is included at end of String.
Spaces on line head and line tail are deleted.
```
%P(foo
asd#{1+2} qwe
bar)
# => ["foo", "asd", Proc.new{1+2}, "qwe", "bar"]
%p(foo
asd#{1+2} qwe
bar)
# => ["foo\n", "asd", Proc.new{1+2}, " qwe\n", "bar"]
```

3. ''<<<'' works like here-document.
'\n' is a delimiter, and is included at end of String.
```
<< ["foo\n", " asd", Proc.new{1+2}, "qwe\n", " bar\n"]
```
```
<<<'EOH'
foo
asd#{1+2}qwe
bar
EOH
# => ["foo\n", " asd\#{1+2}qwe\n", " bar\n"]
```