shimxmemo

メモをのこすよ!

Virtual Methods 仮想メソッド

 

 

Scalar Virtual Methods スカラーの仮想メソッド

chunk(size)

値が、特定のサイズのかたまりに分割され、リスト化されます。

[% ccard_no = "1234567824683579";
   ccard_no.chunk(4).join
%]

出力:

1234 5678 2468 3579

サイズが負の数として指定されている場合、テキストは右から左へかたまりにされます。
これは、たとえば、数値の適切なグループを提供します。
(※訳者注:カンマで数値を区切る事と思われる。)

[% number = 1234567;
   number.chunk(-3).join(',')
%]

出力:

1,234,567

collapse

先頭と末尾の空白が削除され、文字列内部の連続した空白が1つの空白に置き換えられた文字列を返します。

[% text = "  The bird\n  is the word" %]
[% text.collapse %]       # The bird is the word

defined

値が定義されている場合にtrueを返します。

[% user = get_user(uid) IF uid.defined %]

dquote

二重引用符をバックスラッシュでエスケープした文字列を返します。 文字列内の改行文字は "\n"で置き換えられます。

[% quote = 'He said "Oh really?"' %]
[% quote.dquote %]        # He said \"Oh really?\"

hash

オリジナルのスカラー値を示すキー値を持つ一つのエントリを含む、ハッシュリファレンスとして値を返します。リストの仮想メソッドと同様に、これは一般的に別のフォーマットへのデータ操作を助けるために使用されています。

lcfirst

最初の文字を小文字に変換した文字列を返します。

[% word = 'BIRD' %]
[% word.lcfirst %]        # bIRD

length

項目の文字列の長さを返します。

[% IF password.length < 8 %]
   Password too short, dumbass!
[% END %]

list

lower

match(pattern, global)

repeat(n)

replace(search, replace)

remove(pattern)

search(pattern)

size

split(pattern)

substr(offset, length, replacement)

squote

trim

ucfirst

upper