別のキーワード
ライブラリ
- ビルトイン (68)
- csv (12)
-
rubygems
/ specification (12) - strscan (12)
クラス
- Array (36)
- CSV (12)
-
Gem
:: Specification (12) -
RubyVM
:: InstructionSequence (24) - StringScanner (12)
オブジェクト
- ENV (8)
キーワード
-
array
_ attributes (12) - clone (4)
- disasm (12)
- disassemble (12)
- generate (12)
- new (48)
検索結果
先頭5件
-
ENV
. dup -> () (18202.0) -
TypeErrorを発生させます。
TypeErrorを発生させます。
3.0 以前では Object.new と同様の ENV とは無関係の有用ではないオブジェクトを返していたため、3.1 からは例外が発生するようになりました。
詳細はENV.cloneを参照してください。
@see ENV.clone -
StringScanner
. new(str , dup = false) -> StringScanner (214.0) -
新しい StringScanner オブジェクトを生成します。
... dup dup は単に無視します。
引数の文字列は複製も freeze もされず、そのまま使います。
//emlist[例][ruby]{
require 'strscan'
s = StringScanner.new('This is an example string')
s.eos? #=> false
p s.scan(/\w+/) #=> "This"
p s.scan(/\w+/) #=>......nil
p s.scan(/\s+/) #=> " "
//}... -
RubyVM
:: InstructionSequence . disasm(body) -> String (119.0) -
引数 body で指定したオブジェクトから作成した RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字 列に変換して返します。
...c.rb
p = proc { num = 1 + 2 }
puts RubyVM::InstructionSequence.disasm(p)
出力:
== disasm: <RubyVM::InstructionSequence:block in <main>@/tmp/proc.rb>===
== catch table
| catch type: redo st: 0000 ed: 0012 sp: 0000 cont: 0000
| catch type: next st: 0000 ed: 0012 sp: 0000 cont: 0012......1 ( 1)
0002 putobject 1
0004 putobject 2
0006 opt_plus <ic:1>
0008 dup
0009 setlocal num, 0
0012 leave
例2:Method オブジェクトを指定した場合
# /tmp/method.rb
def hello
puts "hell......tmp/method.rb>============
0000 trace 8 ( 1)
0002 trace 1 ( 2)
0004 putself
0005 putstring "hello, world"
0007 send :puts, 1, nil, 8, <ic:0>
0013 trace... -
RubyVM
:: InstructionSequence . disassemble(body) -> String (119.0) -
引数 body で指定したオブジェクトから作成した RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字 列に変換して返します。
...c.rb
p = proc { num = 1 + 2 }
puts RubyVM::InstructionSequence.disasm(p)
出力:
== disasm: <RubyVM::InstructionSequence:block in <main>@/tmp/proc.rb>===
== catch table
| catch type: redo st: 0000 ed: 0012 sp: 0000 cont: 0000
| catch type: next st: 0000 ed: 0012 sp: 0000 cont: 0012......1 ( 1)
0002 putobject 1
0004 putobject 2
0006 opt_plus <ic:1>
0008 dup
0009 setlocal num, 0
0012 leave
例2:Method オブジェクトを指定した場合
# /tmp/method.rb
def hello
puts "hell......tmp/method.rb>============
0000 trace 8 ( 1)
0002 trace 1 ( 2)
0004 putself
0005 putstring "hello, world"
0007 send :puts, 1, nil, 8, <ic:0>
0013 trace... -
Array
. new(ary) -> Array (117.0) -
指定された配列 ary を複製して返します。 Array#dup 同様 要素を複製しない浅い複製です。
...します。
Array#dup 同様 要素を複製しない浅い複製です。
@param ary 複製したい配列を指定します。
//emlist[例][ruby]{
p Array.new([1,2,3]) # => [1,2,3]
a = ["a", "b", "c"]
b = Array.new(a)
a.each{|s| s.capitalize! }
p a #=> ["A", "B", "C"]
p......b #=> ["A", "B", "C"] (b は a と要素を共有する)
//}... -
CSV
. generate(str = "" , options = Hash . new) {|csv| . . . } -> String (107.0) -
このメソッドは与えられた文字列をラップして CSV のオブジェクトとしてブロックに渡します。 ブロック内で CSV オブジェクトに行を追加することができます。 ブロックを評価した結果は文字列を返します。
...ます。
このメソッドに与えられた文字列は変更されるので、新しい文字列オブジェクトが必要な
場合は Object#dup で複製してください。
@param str 文字列を指定します。デフォルトは空文字列です。
@param options CSV.new のオプ......uzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS
csv = CSV.generate(text, headers: true) do |csv|
csv.add_row(["5", "saburo", "kondo", "34"])
end
print csv
# => id,first name,last name,age
# 1,taro,tanaka,20
# 2,jiro,suzuki,18
# 3,ami,sato,19
# 4,yumi,adachi,21
# 5,saburo,kondo,34
//}
@see CSV.new......ます。
このメソッドに与えられた文字列は変更されるので、新しい文字列オブジェクトが必要な
場合は Object#dup で複製してください。
@param str 文字列を指定します。デフォルトは空文字列です。
2.5.0 では不具合... -
ENV
. clone(freeze: true) -> object (107.0) -
ENV オブジェクトの複製を作成して返します。
...複製で環境変数を操作するときに deprecated 警告がでます。
テスト実行中に環境変数を退避する用途には ENV.to_h を使用してください。
//emlist[][ruby]{
saved_env = ENV.to_h
# (テストなど)
ENV.replace(saved_env)
//}
@see Object#clone
@see ENV.dup... -
Gem
:: Specification . array _ attributes -> Array (107.0) -
@@array_attributes の複製を返します。
...@@array_attributes の複製を返します。
@see Object#dup... -
Array
. new(size = 0 , val = nil) -> Array (102.0) -
長さ size の配列を生成し、各要素を val で初期化して返します。
...定します。
@param val 配列の要素の値を指定します。
//emlist[例][ruby]{
ary = Array.new(3, "foo")
p ary #=> ["foo", "foo", "foo"]
ary[0].capitalize!
p ary #=> ["Foo", "Foo", "Foo"] (各要素は同一のオブジェクトである)
//}... -
Array
. new(size) {|index| . . . } -> Array (102.0) -
長さ size の配列を生成し、各要素のインデックスを引数としてブロックを実行し、 各要素の値をブロックの評価結果に設定します。
...(3){|index| "hoge#{index}"}
p ary #=> ["hoge0", "hoge1", "hoge2"]
//}
//emlist[例][ruby]{
ary = Array.new(3){ "foo" }
p ary #=> ["foo", "foo", "foo"]
ary[0].capitalize!
p ary #=> ["Foo", "foo", "foo"] (各要素は違うオブジェ...