55件ヒット
[1-55件を表示]
(0.096秒)
ライブラリ
- psych (11)
-
rexml
/ document (33) - stringio (11)
キーワード
- Default (11)
- Emitter (11)
- Pretty (11)
- Transitive (11)
検索結果
先頭5件
-
StringIO (38043.0)
-
文字列に IO と同じインタフェースを持たせるためのクラスです。
...です。
//emlist[例][ruby]{
require "stringio"
sio = StringIO.new("hoge", 'r+')
p sio.read #=> "hoge"
sio.rewind
p sio.read(1) #=> "h"
sio.write("OGE")
sio.rewind
p sio.read #=> "hOGE"
//}
=== 例外
StringIO オブジェクトは大抵の場合 IO......オブジェクトと同じ例外を発生させます。
例えば次の例では write は IOError を発生させます。
//emlist[例][ruby]{
require "stringio"
sio = StringIO.new("hoge")
sio.close
sio.write("a")
# => in `write': not opened for writing (IOError)
//}... -
REXML
:: Formatters :: Default (55.0) -
XMLドキュメントを(文字列として)出力するクラスです。
...ument.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
defau......, "/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"
//}... -
Psych
:: Emitter (37.0) -
Psych::Parser でパースし、生じたイベントから YAML ドキュメントを再構築するようなハンドラです。
...YAML ドキュメントを入力し、
再構築した YAML ドキュメントを STDERR に出力します。
parser = Psych::Parser.new(Psych::Emitter.new($stderr))
parser.parse($stdin)
また、以下のようにイベントを手動で発生させることで
YAML ドキュメントを構......各メソッドの意味については Psych::Handler を参照してください。
require 'psych'
require 'stringio'
output = StringIO.new
emitter = Psych::Emitter.new(output)
emitter.start_stream(Psych::Parser::UTF8)
emitter.start_document([1, 1], [], false)
emitter.start_m... -
REXML
:: Formatters :: Transitive (37.0) -
XMLドキュメントをテキストの内容を変えずに 多少の整形を加えて出力するクラスです。
...l/document'
require 'rexml/formatters/transitive'
doc = REXML::Document.new <<EOS
<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><c......rint output.string
# >> <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 />... -
REXML
:: Formatters :: Pretty (25.0) -
XMLドキュメントを(文字列として)見た目良く出力するクラスです。
...'rexml/document'
require 'rexml/formatters/pretty'
doc = REXML::Document.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 <childr...