別のキーワード
クラス
- Array (36)
- CSV (12)
-
RubyVM
:: InstructionSequence (24) - StringScanner (12)
オブジェクト
- ENV (4)
キーワード
- clone (4)
- disasm (12)
- disassemble (12)
- generate (12)
- new (48)
検索結果
先頭5件
-
RubyVM
:: InstructionSequence . disasm(body) -> String (3007.0) -
引数 body で指定したオブジェクトから作成した RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字 列に変換して返します。
...た
RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字
列に変換して返します。
@param body Proc、Method オブジェクトを指定します。
例1:Proc オブジェクトを指定した場合
# /tmp/proc.rb
p = proc { num = 1 + 2 }
puts RubyVM::I......nstructionSequence.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
|--------------------------------------------......lus <ic:1>
0008 dup
0009 setlocal num, 0
0012 leave
例2:Method オブジェクトを指定した場合
# /tmp/method.rb
def hello
puts "hello, world"
end
puts RubyVM::InstructionSequence.disasm(method(:hello))
出力:
== disasm: <RubyVM::InstructionSequence:... -
RubyVM
:: InstructionSequence . disassemble(body) -> String (3007.0) -
引数 body で指定したオブジェクトから作成した RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字 列に変換して返します。
...た
RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字
列に変換して返します。
@param body Proc、Method オブジェクトを指定します。
例1:Proc オブジェクトを指定した場合
# /tmp/proc.rb
p = proc { num = 1 + 2 }
puts RubyVM::I......nstructionSequence.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
|--------------------------------------------......lus <ic:1>
0008 dup
0009 setlocal num, 0
0012 leave
例2:Method オブジェクトを指定した場合
# /tmp/method.rb
def hello
puts "hello, world"
end
puts RubyVM::InstructionSequence.disasm(method(:hello))
出力:
== disasm: <RubyVM::InstructionSequence:... -
StringScanner
. new(str , dup = false) -> StringScanner (120.0) -
新しい StringScanner オブジェクトを生成します。
...。
@param str スキャン対象の文字列を指定します。
@param dup dup は単に無視します。
引数の文字列は複製も freeze もされず、そのまま使います。
//emlist[例][ruby]{
require 'strscan'
s = StringScanner.new('This is an example string')
s.eo... -
Array
. new(ary) -> Array (26.0) -
指定された配列 ary を複製して返します。 Array#dup 同様 要素を複製しない浅い複製です。
...指定された配列 ary を複製して返します。
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... -
Array
. new(size) {|index| . . . } -> Array (16.0) -
長さ size の配列を生成し、各要素のインデックスを引数としてブロックを実行し、 各要素の値をブロックの評価結果に設定します。
...ます。
@param size 配列の長さを数値で指定します。
//emlist[例][ruby]{
ary = Array.new(3){|index| "hoge#{index}"}
p ary #=> ["hoge0", "hoge1", "hoge2"]
//}
//emlist[例][ruby]{
ary = Array.new(3){ "foo" }
p ary #=> ["foo", "foo", "foo"]... -
CSV
. generate(str = "" , options = Hash . new) {|csv| . . . } -> String (13.0) -
このメソッドは与えられた文字列をラップして CSV のオブジェクトとしてブロックに渡します。 ブロック内で CSV オブジェクトに行を追加することができます。 ブロックを評価した結果は文字列を返します。
...ます。
このメソッドに与えられた文字列は変更されるので、新しい文字列オブジェクトが必要な
場合は Object#dup で複製してください。
@param str 文字列を指定します。デフォルトは空文字列です。
@param options CSV.new のオプ......ーディングを持つ文字列を出力する場合は、このヒントを
指定する必要があります。
//emlist[例][ruby]{
require "csv"
text =<<-EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS
csv = CSV.generate(te......ます。
このメソッドに与えられた文字列は変更されるので、新しい文字列オブジェクトが必要な
場合は Object#dup で複製してください。
@param str 文字列を指定します。デフォルトは空文字列です。
2.5.0 では不具合... -
ENV
. clone(freeze: true) -> object (13.0) -
ENV オブジェクトの複製を作成して返します。
...複製で環境変数を操作するときに deprecated 警告がでます。
テスト実行中に環境変数を退避する用途には ENV.to_h を使用してください。
//emlist[][ruby]{
saved_env = ENV.to_h
# (テストなど)
ENV.replace(saved_env)
//}
@see Object#clone
@see ENV.dup... -
Array
. new(size = 0 , val = nil) -> Array (11.0) -
長さ size の配列を生成し、各要素を val で初期化して返します。
...を指します。
@param size 配列の長さを数値で指定します。
@param val 配列の要素の値を指定します。
//emlist[例][ruby]{
ary = Array.new(3, "foo")
p ary #=> ["foo", "foo", "foo"]
ary[0].capitalize!
p ary #=> ["Foo", "Foo", "Fo...