ToFormattedString メソッドをどんな時に、何の為に使うのかが理解できません。
検索してみると下記のような説明文がヒットしましたが理解が出来ません・・。
もう少し簡単にわかりやすく教えていただけませんでしょうか?
目的
項目属性/変数の Picture を値に適用した結果の文字列を返します。
構文
att | &var.ToFormattedString()
戻される値のタイプ:
Character
説明
この関数は項目属性または変数をパラメーターとして受け取り、項目属性/変数の Picture を値に適用した結果の文字列を返します。
数値、Date、DateTime、Char、および VarChar タイプの項目属性/変数に適用できます。Date および DateTime タイプの項目属性/変数の場合、返される日付および時間のフォーマットは [ Date Format ] および [ Time Format ] プロパティ (ナレッジベースで設定された言語に基づく) に基づきます。
例
"Z,ZZZ,ZZ9.99" という画像の変数 &Total (10, 2) の値が 4395.35 だとすると、&Total.ToFormattedString()メソッドは、" 4,395.35" という文字列を返します。
11/19 追記
-- coding: utf-8 --
require 'date'
class BookInfo
def initialize( title, author, page, publish_date )
@title = title
@author = author
@page = page
@publish_date = publish_date
end
attr_accessor :title, :author, :page, :publish_date
def to_s
"#{@title}, #{@author}, #{@page}, #{@publish_date}"
end
def toFormattedString( sep = "\n" )
"書籍名: #{@title}#{sep}著者名: #{@author}#{sep}ページ数: #{@page}ページ#{sep}発刊日: #{@publish_date}#{sep}"
end
end
book_info = BookInfo.new(
"ドラゴンポール",
"鳥山 あきお",
248,
Date.new( 2010, 10, 25 ) )
puts book_info.to_s
puts book_info.toFormattedString
puts book_info.toFormattedString( "/" )
以上です。
回答1件
あなたの回答
tips
プレビュー