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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: صفحة الصنف <code>Location</code> في روبي}}</noinclude> تصنيف: Ruby تصنيف: Ruby Locationتمثّل كائنا...')
 
ط (مراجعة وتدقيق.)
 
(مراجعة متوسطة واحدة بواسطة مستخدم واحد آخر غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: صفحة الصنف <code>Location</code> في روبي}}</noinclude>
+
<noinclude>{{DISPLAYTITLE:الصنف <code>Location</code> في روبي}}</noinclude>
 
[[تصنيف: Ruby]]
 
[[تصنيف: Ruby]]
[[تصنيف: Ruby Location]]تمثّل كائنات الصنف [[Ruby/Location|Location]] أُطُر التكديس (stack frames)، وتُنشأ بواسطة <code>[[Ruby/Kernel/caller_locations|Kernel#caller_locations]]</code>.
+
[[تصنيف: Ruby Class]]
 +
[[تصنيف: Ruby Location]]
 +
تمثّل كائنات الصنف <code>Location</code> إطارات المكدس (stack frames)، وتُنشأ بواسطة التابع <code>[[Ruby/Kernel/caller_locations|Kernel.caller_locations]]</code>.
  
مثلا:
+
إليك مثلًا الشيفرة التالية:
 
<syntaxhighlight lang="ruby"># caller_locations.rb
 
<syntaxhighlight lang="ruby"># caller_locations.rb
 
def a(skip)
 
def a(skip)
سطر 18: سطر 20:
 
end‎</syntaxhighlight>  
 
end‎</syntaxhighlight>  
 
تشغيل الأمر <code>ruby caller_locations.rb</code> سوف ينتج:
 
تشغيل الأمر <code>ruby caller_locations.rb</code> سوف ينتج:
<syntaxhighlight lang="ruby">caller_locations.rb:2:in `a'
+
<syntaxhighlight lang="text">caller_locations.rb:2:in `a'
 
caller_locations.rb:5:in `b'
 
caller_locations.rb:5:in `b'
 
caller_locations.rb:8:in `c'‎</syntaxhighlight>  
 
caller_locations.rb:8:in `c'‎</syntaxhighlight>  
سطر 33: سطر 35:
 
end‎</syntaxhighlight>  
 
end‎</syntaxhighlight>  
 
الآن، إن قمت بتنفيذ <code>ruby foo.rb</code>، فيجب أن ترى المخرجات التالية:
 
الآن، إن قمت بتنفيذ <code>ruby foo.rb</code>، فيجب أن ترى المخرجات التالية:
<syntaxhighlight lang="ruby">init.rb:4:in `initialize'
+
<syntaxhighlight lang="text">init.rb:4:in `initialize'
 
init.rb:8:in `new'
 
init.rb:8:in `new'
 
init.rb:8:in `<main>'‎</syntaxhighlight>
 
init.rb:8:in `<main>'‎</syntaxhighlight>
==توابع الصنف العامة (Public Class Methods)==
+
==توابع النسخة العامة==
===[[Ruby/Location/absolute_path | التابع absolute_path]]===
+
===[[Ruby/Location/absolute_path |<code>absolute_path</code>]]===
يُعيد التابع <code>absolute_path</code> مسار الملف الكامل الملف لل[[Ruby/Location|إطار]].
+
يُعيد مسار الملف الكامل للإطار.
===[[Ruby/Location/base_label | التابع base_label]]===
+
===[[Ruby/Location/base_label |<code>base_label</code>]]===
يعيد التابع <code>base_label</code> التسمية الأساسية (base label) لهذا [[Ruby/Location|الإطار]].
+
يعيد التسمية الأساسية (base label) لهذا الإطار.
===[[Ruby/Location/inspect | التابع inspect]]===
+
===[[Ruby/Location/inspect |<code>inspect</code>]]===
يُعيد التابع <code>inspect</code> نفس نتيجة استدعاء <code>inspect</code> على التمثيل النصي للتابع to_str
+
يُعيد نفس نتيجة استدعاء <code>inspect</code> مع السلسلة النصية التي يعيدها التابع <code>to_str</code>.
===[[Ruby/Location/label | التابع label]]===
+
===[[Ruby/Location/label |<code>label</code>]]===
يعيد التابع <code>label</code> تسمية هذا [[Ruby/Location|الإطار]].
+
يعيد تسمية هذا الإطار.
===[[Ruby/Location/lineno | التابع lineno]]===
+
===[[Ruby/Location/lineno |<code>lineno</code>]]===
يعيد التابع <code>lineno</code> رقم سطر هذا [[Ruby/Location|الإطار]].
+
يعيد رقم سطر هذا الإطار.
===[[Ruby/Location/path | التابع path]]===
+
===[[Ruby/Location/path |<code>path</code>]]===
يُعيد اسم ملف هذا [[Ruby/Location|الإطار]].
+
يُعيد اسم ملف هذا الإطار.
===[[Ruby/Location/to_s | التابع to_s]]===
+
===[[Ruby/Location/to_s |<code>to_s</code>]]===
يُعيد التابع <code>to_s</code> [[Ruby/String|سلسلة نصية]] تمثل هذا [[Ruby/Location|الإطار]] على نمط التابع <code>[[Ruby/Kernel/caller|Kernel#caller]]</code> .
+
يُعيد [[Ruby/String|سلسلة نصية]] تمثل هذا الإطار على نمط التابع <code>[[Ruby/Kernel/caller|Kernel.caller]]</code>.
 
==مصادر==
 
==مصادر==
*[http://ruby-doc.org/core-2.5.1/Thread/Backtrace/Location.html قسم  الصنف Location في توثيق روبي الرسمي.]
+
*[http://ruby-doc.org/core-2.5.1/Thread/Backtrace/Location.html صفحة الصنف Location في توثيق روبي الرسمي.]

المراجعة الحالية بتاريخ 09:22، 6 ديسمبر 2018

تمثّل كائنات الصنف Location إطارات المكدس (stack frames)، وتُنشأ بواسطة التابع Kernel.caller_locations.

إليك مثلًا الشيفرة التالية:

# caller_locations.rb
def a(skip)
  caller_locations(skip)
end
def b(skip)
  a(skip)
end
def c(skip)
  b(skip)
end
c(0..2).map do |call|
  puts call.to_s
end

تشغيل الأمر ruby caller_locations.rb سوف ينتج:

caller_locations.rb:2:in `a'
caller_locations.rb:5:in `b'
caller_locations.rb:8:in `c'‎

إليك مثالًا آخر بنتيجة مختلفة بعض الشيء:

# foo.rb
class Foo
  attr_accessor :locations
  def initialize(skip)
    @locations = caller_locations(skip)
  end
end
Foo.new(0..2).locations.map do |call|
  puts call.to_s
end

الآن، إن قمت بتنفيذ ruby foo.rb، فيجب أن ترى المخرجات التالية:

init.rb:4:in `initialize'
init.rb:8:in `new'
init.rb:8:in `<main>'‎

توابع النسخة العامة

absolute_path

يُعيد مسار الملف الكامل للإطار.

base_label

يعيد التسمية الأساسية (base label) لهذا الإطار.

inspect

يُعيد نفس نتيجة استدعاء inspect مع السلسلة النصية التي يعيدها التابع to_str.

label

يعيد تسمية هذا الإطار.

lineno

يعيد رقم سطر هذا الإطار.

path

يُعيد اسم ملف هذا الإطار.

to_s

يُعيد سلسلة نصية تمثل هذا الإطار على نمط التابع Kernel.caller.

مصادر