of

of(p1)
Class Public methods

Returns the instruction sequence containing the given proc or method.

For example, using irb:

1
2
3
4
5
6
7
8
9
# 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# /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>
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.