るりまサーチ

最速Rubyリファレンスマニュアル検索!
264件ヒット [1-100件を表示] (0.071秒)
トップページ > クエリ:>[x] > 種類:クラス[x]

別のキーワード

  1. _builtin >
  2. bigdecimal >
  3. float >
  4. module >
  5. integer >

ライブラリ

キーワード

検索結果

<< 1 2 3 > >>

Numeric (31.0)

数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。

...Float などの数値クラス
は Numeric のサブクラスとして実装されています。

演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッドは、サブクラスで提供されているメ...
...れているメソッドは、Numeric のサブクラスとして新たに数値クラスを定義した時に、
演算メソッド(+, -, *, /, %, <=>, coerce)だけを定義すれば、数値クラスのそのほかのメソッドが
適切に定義されることを意図して提供されてい...
...//emlist[例][ruby]{
if n > 0 then
n.ceil
else
n.floor
end
//}

また、任意桁の切上げ、切捨て、四捨五入を行うメソッドは以下のように
定義できます。

//emlist[][ruby]{
class
Numeric
def roundup(d=0)
x = 10**d
if self > 0
self.quo(x).ceil * x...

RDoc::Markup (25.0)

RDoc 形式のドキュメントを目的の形式に変換するためのクラスです。

...:

require 'rdoc/markup'
require 'rdoc/markup/to_html'

class
WikiHtml < RDoc::Markup::ToHtml
# WikiWord のフォントを赤く表示。
def handle_special_WIKIWORD(special)
"<font color=red>" + special.text + "</font>"
end
end

m = RDoc::Markup.new
# { 〜 } まで...
...o> 〜 </no> までを :STRIKE でフォーマットする。
m.add_html("no", :STRIKE)

# WikiWord を追加。
m.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)

wh = WikiHtml.new(m)
# :STRIKE のフォーマットを <strike> 〜 </strike> に指定。
wh.add_tag(:STRIKE, "<strike>"...
..., "</strike>")

puts "<body>#{wh.convert ARGF.read}</body>"

変換する形式を変更する場合、フォーマッタ(例. RDoc::Markup::ToHtml)
を変更、拡張する必要があります。...

REXML::Formatters::Default (25.0)

XMLドキュメントを(文字列として)出力するクラスです。

...L::Document.new <<EOS
<root>
<children>
<grandchildren/>
</children>
</root>
EOS

default_formatter = REXML::Formatters::Default.new
output = StringIO.new
default_formatter.write(doc, output)
output.string
# => "<root>\n<children>\n <grandchildren/>\n</children>\n</root>\n"

output = StringIO.new...
..., "/root/children"), output)
output.string
# => "<children>\n <grandchildren/>\n</children>"

ie_hack_formatter = REXML::Formatters::Default.new(true)
output = StringIO.new
ie_hack_formatter.write(doc, output)
output.string
# => "<root>\n<children>\n <grandchildren />\n</children>\n</root>\n"
//}...

REXML::Formatters::Pretty (25.0)

XMLドキュメントを(文字列として)見た目良く出力するクラスです。

...new <<EOS
<root>
<children>
<grandchildren foo='bar'/>
</children>
</root>
EOS

pretty_formatter = REXML::Formatters::Pretty.new
output = StringIO.new
pretty_formatter.write(doc, output)
output.string
# => "<root>\n <children>\n <grandchildren foo='bar'/>\n </children>\n</root>"
# この出...

REXML::Formatters::Transitive (25.0)

XMLドキュメントをテキストの内容を変えずに 多少の整形を加えて出力するクラスです。

...OS
<root><children>
<grandchildren foo='bar' />
</children></root>
EOS

transitive_formatter = REXML::Formatters::Transitive.new
output = StringIO.new
transitive_formatter.write(doc, output)
output.string
# => "<root\n><children\n >\n<grandchildren foo='bar'\n />\n</children\n ></root\n>\n"
pri...
...g
# >> <root
# >> ><children
# >> >
# >> <grandchildren foo='bar'
# >> />
# >> </children
# >> ></root
# >> >

output = StringIO.new
transitive_formatter.write(REXML::XPath.first(doc, "/root/children"), output)
output.string
# => "<children\n>\n<grandchildren foo='bar'\n />\n</children\n>"...

絞り込み条件を変える

Encoding::UndefinedConversionError (19.0)

エンコーディング変換後の文字が存在しない場合に発生する例外。

...しかない文字を EUC-JP に変換しようとした場合などに発生します。

//emlist[例][ruby]{
"\u2603".encode(Encoding::EUC_JP)
#=> Encoding::UndefinedConversionError: U+2603 from UTF-8 to EUC-JP
//}


変換が多段階でなされ、その途中で例外が生じた場合は、...
...# ISO-8859-1 -> UTF-8 -> EUC-JP
begin
ec.convert("\xa0")
# NO-BREAK SPACE, which is available in UTF-8 but not in EUC-JP.
rescue Encoding::UndefinedConversionError
p $!.source_encoding #=> #<Encoding:UTF-8>
p $!.destination_encoding #=> #<Encoding:EUC-JP>
p $!.source_...
...encoding_name #=> "UTF-8"
p $!.destination_encoding_name #=> "EUC-JP"
puts $!.error_char.dump #=> "\u{a0}"
p $!.error_char.encoding #=> #<Encoding:UTF-8>
end
//}...

IO (13.0)

基本的な入出力機能のためのクラスです。

...動作します。

例:

f = File.open('t.txt', 'r+:euc-jp')
p f.getc.encoding #=> Encoding::EUC_JP
p f.read(1).encoding #=> Encoding::ASCII_8BIT

====[a:io_encoding] IO のエンコーディングとエンコーディングの変換

IO...
...le1')
p f.getc.encoding #=> Encoding::EUC_JP

例2:

f = File.open('t.txt', 'w+:shift_jis:euc-jp')
f.write "\xB4\xC1\xBB\xFA" # 文字列 "漢字" の EUC-JP リテラル
f.rewind
s = f.read(4)
puts s.dump #=> "\x8A\xBF\x8E\x9A"...
...プション -E で指定します。
-E が指定されなかった場合は次のような優先順位で決定されます。

-E (最優先) > -K > locale

==== ファイル名のエンコーディング

ファイル名の文字エンコーディングはプラットフォームに依存しま...

IPAddr (13.0)

IP アドレスを扱うのためのクラスです。

...quire 'ipaddr'

ipaddr1 = IPAddr.new("3ffe:505:2::1")
p ipaddr1 # => #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>

ipaddr3 = IPAddr.new("192.168.2.0/24")
p ipaddr3 # => #<IPAddr: IPv4:192.168.2.0/255.255.255.0>

=== 参照

* 3513...

Method (13.0)

Object#method によりオブジェクト化され たメソッドオブジェクトのクラスです。

...ソッドを Method オブジェクト化する。

//emlist[例][ruby]{
class
Foo
def foo(arg)
"foo called with arg #{arg}"
end
end

m = Foo.new.method(:foo)

p m # => #<Method: Foo#foo>
p m.call(1) # => "foo called with arg 1"
//}

名前のないメソッド(の代わり)...
...new {|arg|
"proc called with arg #{arg}"
}

p pr # => #<Proc:0x401b1fcc>
p pr.call(1) # => "proc called with arg 1"
//}

Method オブジェクトが有用なのは以下のような場合。

//emlist[例][ruby]{
class
Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz...
...しておく
methods = {1 => obj.method(:foo),
2 => obj.method(:bar),
3 => obj.method(:baz)}

# キーを使って関連するメソッドを呼び出す
p methods[1].call # => "foo"
p methods[2].call # => "bar"
p methods[3].call # => "baz"
//}

しかし、...
<< 1 2 3 > >>