Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions core/ruby_vm.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,46 @@ class RubyVM::InstructionSequence < Object
# event_symbol] pair.
#
def trace_points: () -> Array[untyped]

# <!--
# rdoc-file=iseq.c
# - of(p1)
# -->
# Returns the instruction sequence containing the given proc or method.
#
# For example, using irb:
#
# # a proc
# > p = proc { num = 1 + 2 }
# > RubyVM::InstructionSequence.of(p)
# > #=> <RubyVM::InstructionSequence:block in irb_binding@(irb)>
#
# # for a method
# > def foo(bar); puts bar; end
# > RubyVM::InstructionSequence.of(method(:foo))
# > #=> <RubyVM::InstructionSequence:foo@(irb)>
#
# Using ::compile_file:
#
# # /tmp/iseq_of.rb
# def hello
# puts "hello, world"
# end
#
# $a_global_proc = proc { str = 'a' + 'b' }
#
# # in irb
# > require '/tmp/iseq_of.rb'
#
# # first the method hello
# > RubyVM::InstructionSequence.of(method(:hello))
# > #=> #<RubyVM::InstructionSequence:0x007fb73d7cb1d0>
#
# # then the global proc
# > RubyVM::InstructionSequence.of($a_global_proc)
# > #=> #<RubyVM::InstructionSequence:0x007fb73d7caf78>
#
def self.of: (Proc | Method | UnboundMethod body) -> RubyVM::InstructionSequence?
end

# <!-- rdoc-file=ast.rb -->
Expand Down
16 changes: 16 additions & 0 deletions test/stdlib/RubyVM_InstructionSequence_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require_relative "test_helper"

class RubyVM::InstructionSequenceSingletonTest < Test::Unit::TestCase
include TestHelper

testing "singleton(::RubyVM::InstructionSequence)"

def test_of
assert_send_type "(::Method body) -> ::RubyVM::InstructionSequence",
RubyVM::InstructionSequence, :of, method(:test_of)
assert_send_type "(::UnboundMethod body) -> ::RubyVM::InstructionSequence",
RubyVM::InstructionSequence, :of, self.class.instance_method(:test_of)
assert_send_type "(::Proc body) -> ::RubyVM::InstructionSequence",
RubyVM::InstructionSequence, :of, -> { }
end
end
Loading