الفرق بين المراجعتين ل"Ruby/InstructionSequence/of"
< Ruby | InstructionSequence
اذهب إلى التنقل
اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع <code>of</code> الخاص بالصنف <code>InstructionSequence</code> في روبي}}</noinclude> تصنيف: Ruby [...') |
جميل-بيلوني (نقاش | مساهمات) ط (مراجعة وتدقيق.) |
||
(مراجعة متوسطة واحدة بواسطة مستخدم واحد آخر غير معروضة) | |||
سطر 1: | سطر 1: | ||
− | <noinclude>{{DISPLAYTITLE: التابع <code>of | + | <noinclude>{{DISPLAYTITLE: التابع <code>InstructionSequence.of</code> في روبي}}</noinclude> |
[[تصنيف: Ruby]] | [[تصنيف: Ruby]] | ||
[[تصنيف: Ruby Method]] | [[تصنيف: Ruby Method]] | ||
[[تصنيف: Ruby InstructionSequence]] | [[تصنيف: Ruby InstructionSequence]] | ||
− | يُعيد التابع <code>of</code> [[Ruby/InstructionSequence|سلسلة التعليمات]] التي | + | يُعيد التابع <code>of</code> [[Ruby/InstructionSequence|سلسلة التعليمات]] التي تحوي الكائن <code>[[Ruby/Proc|Proc]]</code> أو <code>[[Ruby/Method|Method]]</code> المعطى. |
− | على | + | ==البنية العامة== |
− | <syntaxhighlight lang="ruby"># a proc | + | <syntaxhighlight lang="ruby">of(p1)</syntaxhighlight> |
+ | |||
+ | == أمثلة == | ||
+ | مثال على استعمال التابع <code>of</code> باستخدام <code>irb</code>:<syntaxhighlight lang="ruby"># a proc | ||
> p = proc { num = 1 + 2 } | > p = proc { num = 1 + 2 } | ||
> RubyVM::InstructionSequence.of(p) | > RubyVM::InstructionSequence.of(p) | ||
سطر 13: | سطر 16: | ||
> RubyVM::InstructionSequence.of(method(:foo)) | > RubyVM::InstructionSequence.of(method(:foo)) | ||
> #=> <RubyVM::InstructionSequence:foo@(irb)></syntaxhighlight> | > #=> <RubyVM::InstructionSequence:foo@(irb)></syntaxhighlight> | ||
− | أو باستخدام <code>[[Ruby/InstructionSequence/compile_file| | + | أو باستخدام <code>[[Ruby/InstructionSequence/compile_file|compile_file]]</code>: |
<syntaxhighlight lang="ruby"># /tmp/iseq_of.rb | <syntaxhighlight lang="ruby"># /tmp/iseq_of.rb | ||
def hello | def hello | ||
سطر 27: | سطر 30: | ||
> RubyVM::InstructionSequence.of($a_global_proc) | > RubyVM::InstructionSequence.of($a_global_proc) | ||
> #=> #<RubyVM::InstructionSequence:0x007fb73d7caf78></syntaxhighlight> | > #=> #<RubyVM::InstructionSequence:0x007fb73d7caf78></syntaxhighlight> | ||
− | + | ==انظر أيضًا== | |
− | + | * التابع <code>[[Ruby/InstructionSequence/new|new]]</code>: ينشئ كائنًا من النوع <code>[[Ruby/InstructionSequence|InstructionSequence]]</code>. | |
− | |||
− | |||
− | ==انظر | ||
− | * التابع <code>[[Ruby/InstructionSequence/new|new]]</code>: | ||
− | |||
==مصادر== | ==مصادر== | ||
− | *[http://ruby-doc.org/core-2.5.1/RubyVM/InstructionSequence.html#method-c-of قسم | + | *[http://ruby-doc.org/core-2.5.1/RubyVM/InstructionSequence.html#method-c-of قسم التابع of في الصنف InstructionSequence في توثيق روبي الرسمي.] |
المراجعة الحالية بتاريخ 07:24، 4 ديسمبر 2018
يُعيد التابع of
سلسلة التعليمات التي تحوي الكائن Proc
أو Method
المعطى.
البنية العامة
of(p1)
أمثلة
مثال على استعمال التابع of
باستخدام 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
: ينشئ كائنًا من النوعInstructionSequence
.