クラス
- Symbol (11)
- Thread (22)
-
Thread
:: Backtrace :: Location (22)
モジュール
- Kernel (11)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - BlockCaller (11)
- Closure (11)
- Location (11)
- MonitorMixin (11)
-
NEWS for Ruby 2
. 5 . 0 (7) -
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) -
add
_ trace _ func (11) - inspect (11)
- profile (6)
-
ruby 1
. 6 feature (11) -
set
_ trace _ func (22) -
to
_ proc (11) - メソッド呼び出し(super・ブロック付き・yield) (9)
検索結果
先頭5件
-
Thread
:: Backtrace :: Location # to _ s -> String (18119.0) -
self が表すフレームを Kernel.#caller と同じ表現にした文字列を返し ます。
...レームを Kernel.#caller と同じ表現にした文字列を返し
ます。
//emlist[例][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end
Foo.new(0..2).locations.map do |call|
puts call.to_s
end
# => path/to/foo.... -
Fiddle
:: Closure :: BlockCaller (6024.0) -
Ruby のブロックをラップしたコールバック関数を表すクラスです。
...[TYPE_VOIDP, TYPE_INT, TYPE_INT, TYPE_VOIDP],
TYPE_VOID)
compare = Fiddle::Closure::BlockCaller.new(TYPE_INT, [TYPE_VOIDP, TYPE_VOIDP]){|x, y|
# qsort の比較関数は 型が int(*)(void*, void*) であるため、
# このブロ......は DL::CPtr オブジェクトが渡される。
# そのポインタが指す先は比較している文字なので、
# DL::CPtr#to_s で1文字の文字列に変換している
x.to_s(1) <=> y.to_s(1)
}
s = "7x0cba(Uq)"
qs.call(s, s.size, 1, compare)
p s # => "()07Uabcqx"... -
メソッド呼び出し(super・ブロック付き・yield) (3070.0)
-
メソッド呼び出し(super・ブロック付き・yield) * super * block * yield * block_arg * numbered_parameters * call_method
...メソッド呼び出し(super・ブロック付き・yield)
* super
* block
* yield
* block_arg
* numbered_parameters
* call_method
//emlist[例][ruby]{
foo.bar()
foo.bar
bar()
print "hello world\n"
print
Class.new
Class::new
//}
文法:
[式 `.'] 識別子 [`(' [[`*']......す
レシーバが nil でない場合は通常のメソッド呼び出しが行われます。
//emlist[][ruby]{
foo = 13
foo&.to_s # => "13"
foo = nil
foo&.to_s # nil, not ""
//}
`&.' は要素代入(アトリビュート)に対しても使えます。
//emlist[][ruby]{
foo&.bar = "abc" # for......p b # => "b"
}
//}
===[a:call_method] .() および ::() 形式のメソッド呼び出し(callメソッドの糖衣構文)
下記はcallメソッドの糖衣構文です。
Proc#callにも言及がありますが、Proc以外のオブジェクトに対しても(callメソッドさえ定義... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (126.0) -
1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))
...クがゆるい。break が例外になる。
Proc.new {|a,b,c| p [a,b,c]}.call(1,2)
=> -:1: wrong # of arguments (2 for 3) (ArgumentError)
from -:1:in `call'
from -:1
ruby 1.6.8 (2002-12-24) [i586-linux]......=> ruby 1.8.0 (2003-06-21) [i586-linux]
[1, 2, nil]
Proc.new { break }.call
=> ruby 1.6.8 (2002-12-24) [i586-linux]
=> -:1:in `call': break from proc-closure (LocalJumpError)
from -:1
ruby 1.......yield の戻り値になります。
: to_str [compat]
to_str を定義したオブジェクトはより広範囲にStringとして振舞うように
なりました。
文字列を引数に取るほとんどの組み込みメソッドは、to_str による暗黙の
型変換を試... -
NEWS for Ruby 2
. 7 . 0 (78.0) -
NEWS for Ruby 2.7.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...Numbered parameters)がデフォルトのブロックの仮引数として
導入されました。 4475
//emlist[][ruby]{
[1, 2, 10].map { _1.to_s(16) } #=> ["1", "2", "a"]
[[1, 2], [3, 4]].map { _1 + _2 } #=> [3, 7]
//}
* 「_1」などはまだローカル変数名として使えて......た。 15323
* Enumerable#tallyが追加されました。 11076
//emlist[Enumerable#filter_map][ruby]{
[1, 2, 3].filter_map {|x| x.odd? ? x.to_s : nil } #=> ["1", "3"]
//}
//emlist[Enumerable#tally][ruby]{
["A", "B", "C", "B", "A"].tally #=> {"A"=>2, "B"=>2, "C"=>1}
//}
* Enumerator
*......nspectがTime#to_sから分離されて、秒未満も
含まれるようになりました。 15958
* UnboundMethod
* 新規メソッド
* UnboundMethod#bind_callが追加されました。 15955
* 「umethod.bind_call(obj, ...)」は「umethod.bind(obj).call(...)」と... -
Kernel
. # set _ trace _ func(proc) -> Proc (66.0) -
Ruby インタプリタのイベントをトレースする Proc オブジェクトとして 指定された proc を登録します。 nil を指定するとトレースがオフになります。
...表す、以下のいずれかの文字列。
//emlist{
"line": 式の評価。
"call": メソッドの呼び出し。
"return": メソッド呼び出しからのリターン。
"c-call": Cで記述されたメソッドの呼び出し。
"c-return": Cで記述されたメ......ist{
line
最後に呼び出されたメソッドを表す Symbol オブジェクト。
トップレベルでは nil。
call/return/c-call/c-return
呼び出された/リターンするメソッドを表す Symbol オブジェクト。
class/end
nil。......ist[例][ruby]{
set_trace_func lambda {|*arg|
p arg
}
class Foo
end
43.to_s
# ----結果----
# ["c-return", "..", 1, :set_trace_func, #<Binding:0xf6ceb8>, Kernel]
# ["line", "..", 4, nil, #<Binding:0x10cbcd8>, nil]
# ["c-call", "..", 4, :inherited, #<Binding:0x10cba98>, Class]
# ["c-return", ".."... -
Fiddle
:: Closure (54.0) -
コールバック関数を表すクラスです。
...ラスです。
Ruby のメソッド(call)を C の関数ポインタとして表現するためのクラスです。
FFI の closure の wrapper です。
利用法としては、このクラスのサブクラスを作って
そのサブクラスに call メソッドを定義し、
new でオブ......れる。
# そのポインタが指す先は比較している文字なので、
# DL::CPtr#to_s で1文字の文字列に変換している
def call(x, y)
x.to_s(1) <=> y.to_s(1)
end
end
libc = DL.dlopen("/lib/libc.so.6")
qs = Fiddle::Function.new(libc["qsort"],......[TYPE_VOIDP, TYPE_INT, TYPE_INT, TYPE_VOIDP],
TYPE_VOID)
s = "7x0cba(Uq)"
qs.call(s, s.size, 1, Compare.new(TYPE_INT, [TYPE_VOIDP, TYPE_VOIDP]))
p s # => "()07Uabcqx"
Class.new を使うことで、サブクラスを明示的に作ること... -
NEWS for Ruby 3
. 0 . 0 (54.0) -
NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...ocs
accepting a single rest argument and no keywords.
16166
//emlist[][ruby]{
pr = proc{|*a, **kw| [a, kw]}
pr.call([1])
# 2.7 => [[1], {}]
# 3.0 => [[[1]], {}]
pr.call([1, {a: 1}])
# 2.7 => [[1], {:a=>1}] # and deprecation warning
# 3.0 => a=>1}, {}]
//}
* Arguments forwarding (`...`)......== Core classes updates
Outstanding ones only.
* Array
* The following methods now return Array instances instead of subclass instances when called on subclass instances: 6087
* Array#drop
* Array#drop_while
* Array#flatten
* Array#slice!
* Array#slice / Array#[......tinuously improve the coverage of language features, analysis performance, and usability.
//emlist[][ruby]{
# test.rb
def foo(x)
if x > 10
x.to_s
else
nil
end
end
foo(42)
//}
//emlist{
$ typeprof test.rb
# Classes
class Object
def foo : (Integer) -> String?
end
//}
== Miscellaneo... -
ruby 1
. 6 feature (54.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...-:9: warning: p (...) interpreted as method call
ruby 1.6.5 (2001-09-19) [i586-linux]
Bar
[1, 2, 3]
Bar
Array
Array
Array
=> -:9: warning: p (...) interpreted as method call
ruby 1.6.5 (2001-10-05) [i586-......e Foo
def foo
:foo
end
end
class Bar
include Foo
end
m = Foo.instance_method :foo
p m.bind(Bar.new).call
=> ruby 1.6.4 (2001-06-04) [i586-linux]
-:12:in `bind': first argument must be an instance of Foo (TypeError)
from -:12......可能ということです)
require 'resolv'
p Resolv.new.getaddress("www.ruby-lang.org").to_s
=> /usr/local/lib/ruby/1.6/resolv.rb:160: warning: timeout (...) interpreted as method call
/usr/local/lib/ruby/1.6/resolv.rb:55: warning: instance variable @initialized not initializ... -
Thread
# set _ trace _ func(pr) -> Proc | nil (48.0) -
スレッドにトレース用ハンドラを設定します。
...[例][ruby]{
th = Thread.new do
class Trace
end
2.to_s
Thread.current.set_trace_func nil
3.to_s
end
th.set_trace_func lambda {|*arg| p arg }
th.join
# => ["line", "example.rb", 2, nil, #<Binding:0x00007fc8de87cb08>, nil]
# => ["c-call", "example.rb", 2, :inherited, #<Binding:0x00007fc8de8......007fc8de88c440>, nil]
# => ["c-call", "example.rb", 4, :to_s, #<Binding:0x00007fc8de896f30>, Integer]
# => ["c-return", "example.rb", 4, :to_s, #<Binding:0x00007fc8de894a50>, Integer]
# => ["line", "example.rb", 5, nil, #<Binding:0x00007fc8de967b08>, nil]
# => ["c-call", "example.rb", 5, :current, #......<Binding:0x00007fc8de967798>, Thread]
# => ["c-return", "example.rb", 5, :current, #<Binding:0x00007fc8de9673b0>, Thread]
# => ["c-call", "example.rb", 5, :set_trace_func, #<Binding:0x00007fc8de966fc8>, Thread]
//}
@param pr トレースハンドラ(Proc オブジェクト) もしくは nil
@see Th... -
Thread
:: Backtrace :: Location (36.0) -
Ruby のフレームを表すクラスです。
...nel.#caller_locations から生成されます。
//emlist[例1][ruby]{
# caller_locations.rb
def a(skip)
caller_locations(skip)
end
def b(skip)
a(skip)
end
def c(skip)
b(skip)
end
c(0..2).map do |call|
puts call.to_s
end
//}
例1の実行結果:
caller_locations.rb:2:in `a'
caller_l......ocations.rb:5:in `b'
caller_locations.rb:8:in `c'
//emlist[例2][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end
Foo.new(0..2).locations.map do |call|
puts call.to_s
end
//}
例2の実行結果:
init.rb:4:in `ini...