التابع of‎ الخاص بالصنف InstructionSequence في روبي

من موسوعة حسوب
< Ruby‏ | InstructionSequence
مراجعة 22:00، 1 نوفمبر 2018 بواسطة محمد-بغات (نقاش | مساهمات) (أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع <code>of‎</code> الخاص بالصنف <code>InstructionSequence</code> في روبي}}</noinclude> تصنيف: Ruby [...')
(فرق) → مراجعة أقدم | المراجعة الحالية (فرق) | مراجعة أحدث ← (فرق)
اذهب إلى التنقل اذهب إلى البحث

يُعيد التابع of سلسلة التعليمات التي تحتوي كائن proc أو method المعطى. على سبيل المثال، باستخدام 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)>‎

أو باستخدام ::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>‎

البنية العامة


القيمة المُعادة

انظر أيضا

  • التابع new: يأخذ وسيطًا source ، وهو سسس (String) تحتوي أكواد برمجية بلغة روبي، ويُصرّفها (compiles it) إلى كائن من النوع InstructionSequence.
  • التابع absolute_path: يُعيد المسار المطلق لككك (ووو).

مصادر