الفرق بين المراجعتين ل"Ruby/InstructionSequence/of"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع <code>of‎</code> الخاص بالصنف <code>InstructionSequence</code> في روبي}}</noinclude> تصنيف: Ruby [...')
 
ط (مراجعة وتدقيق.)
 
(مراجعة متوسطة واحدة بواسطة مستخدم واحد آخر غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: التابع <code>of‎</code> الخاص بالصنف <code>InstructionSequence</code> في روبي}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: التابع <code>InstructionSequence.of‎</code> في روبي}}</noinclude>
 
[[تصنيف: Ruby]]
 
[[تصنيف: Ruby]]
 
[[تصنيف: Ruby Method]]
 
[[تصنيف: Ruby Method]]
 
[[تصنيف: Ruby InstructionSequence]]
 
[[تصنيف: Ruby InstructionSequence]]
يُعيد التابع <code>of</code> [[Ruby/InstructionSequence|سلسلة التعليمات]] التي تحتوي كائن proc أو method المعطى.
+
يُعيد التابع <code>of</code> [[Ruby/InstructionSequence|سلسلة التعليمات]] التي تحوي الكائن <code>[[Ruby/Proc|Proc]]</code> أو <code>[[Ruby/Method|Method]]</code> المعطى.
على سبيل المثال، باستخدام irb:
+
==البنية العامة==
<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|::compile_file]]</code>:
+
أو باستخدام <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>
==البنية العامة==
+
==انظر أيضًا==
<syntaxhighlight lang="ruby">‎</syntaxhighlight>
+
* التابع <code>[[Ruby/InstructionSequence/new|new]]</code>: ينشئ كائنًا من النوع <code>[[Ruby/InstructionSequence|InstructionSequence]]</code>.
==القيمة المُعادة==
 
 
 
==انظر أيضا==
 
* التابع <code>[[Ruby/InstructionSequence/new|new]]</code>: يأخذ  وسيطًا <code>source</code> ، وهو سسس (<code>[[Ruby/String|String]]</code>) تحتوي أكواد برمجية بلغة روبي، ويُصرّفها (compiles it) إلى كائن من النوع <code>[[Ruby/InstructionSequence|InstructionSequence]]</code>.
 
* التابع <code>[[Ruby/InstructionSequence/absolute_path|absolute_path]]</code>: يُعيد  المسار المطلق لككك (ووو).
 
  
 
==مصادر==
 
==مصادر==
*[http://ruby-doc.org/core-2.5.1/RubyVM/InstructionSequence.html#method-c-of قسم التابع of‎ في الصنف InstructionSequence‎ في توثيق روبي الرسمي.]
+
*[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>‎

انظر أيضًا

مصادر