Reference manuals of the GPhys library(http://ruby.gfd-dennou.org/products/gphys/doc/)の日本語訳です。

Unitsオブジェクトが付いたNumericクラスです。
NumRu::UnitsとRationalに従属する標準ライブラリ。

クラスメソッド

new(val, uni)

コンストラクタ。
引数
  • val (Numeric)
  • units (NumRu::Units or String): 文字列の場合は、内部的にNumRu::Unitsオブジェクトに変換される

[val, uni]

newと同じ。

from_date(date, units)

DateTimeオブジェクト(または、Dateオブジェクト)をUNumericオブジェクトに変換する。
引数
  • date (Date or DateTime)
  • units (Units or String) : 生成するUnumericオブジェクトの単位

メソッド

val

返り値
  • その値 (Numeric)

units

返り値
  • その単位 (NumRu::Units)

inspect

返り値
  • Stringオブジェクト (例;'1 m')

to_s

inspectのエイリアス。

to_f

返り値
  • val.to_f

to_i

返り値
  • val.to_i

convert(to_units)

to_unitsへ変換する。
返り値
  • UNumericオブジェクト
例外
  • 現在の単位がto_unitsと互換性がない場合

convert2

convertと同じだが、単位の互換性がない場合はselfを返す(警告有)。
例外
  • なし
警告発生
以下の状況が満たされる場合、$stderrに警告が発生する。
  • selfの単位に互換性がない

coerce(other)

既知の通り。Numeric、Array、NArrayの各オブジェクトの処理が可能。(VArrayオブジェクトとGPhysオブジェクトはUNumericオブジェクトを知っている)

*(other)

乗算。Numeric、UNumeric、VArray、GPhysの各オブジェクトで可能。単位も計算される。(otherがNumericオブジェクトならば無次元と仮定する)ension)
返り値
  • UNumeric、VArray、GPhysの各オブジェクト

/(other)

除算。*参照。

+(other)

加算。Numeric、Array、NArrayの各オブジェクトの処理が可能。返り値はselfの単位を持つ。
SPECIAL REMARK!
If other has units within a factor and/or offset of difference, It is CONVERTED before addition (by using convert2)!
返り値
UNumeric、VArray、GPhysの各オブジェクト
警告発生
以下の状況が満たされる場合、$stderrに警告が発生する。
  • selfto_unitsの単位に互換性がない
  • otherがNumericオブジェクトである

-(other)

減算。+参照。

**(num)

累乗。

abs

絶対値。その他の数学関数もインスタンスメソッドとして使用可能。

to_datetime(eps_sec=0.0)

時間のUNumericオブジェクトをDateTimeオブジェクトに変換する。
引数
  • eps_sec (Float) : Magic epsilon to prevent the round-off of DateTime [seconds]. Recommended value is 0.1.
返り値
  • DateTimeオブジェクト
例外
raised if self does not have a time unit with a since field

strftime(fmt)

時間のUNumericオブジェクトについての日時および日付のテキスト形式。
self.to_datetime(0.1).strftime(fmt)
のように実装する。
引数
  • fmt (Sting) : フォーマット形式。% man 3 strftimeで書き方を参照
返り値
  • Stringオブジェクト

管理人/副管理人のみ編集できます