الفرق بين المراجعتين لصفحة: «Ruby/Module/class variables»
أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع <code>class_variables</code> الخاص بالصنف <code>Module</code> في روبي}}</noinclude> تصنيف: Ruby [...' |
لا ملخص تعديل |
||
| سطر 3: | سطر 3: | ||
[[تصنيف: Ruby Method]] | [[تصنيف: Ruby Method]] | ||
[[تصنيف: Ruby Module]] | [[تصنيف: Ruby Module]] | ||
يعيد التابع <code>class_variables</code> مصفوفة مكونة من أسماء متغيرات الصنف في الوحدة | يعيد التابع <code>class_variables</code> مصفوفة مكونة من أسماء متغيرات الصنف في الوحدة التي استُدعي معها. يشمل ذلك أسماء متغيرات الصنف في كل الوحدات المُضمّنة، ما لم يتم تعيين الوسيط <code>inherit</code> عند القيمة <code>false</code>. | ||
==البنية العامة== | ==البنية العامة== | ||
<syntaxhighlight lang="ruby">class_variables(inherit=true) → array</syntaxhighlight> | <syntaxhighlight lang="ruby">class_variables(inherit=true) → array</syntaxhighlight> | ||
| سطر 9: | سطر 9: | ||
===<code>inherit</code>=== | ===<code>inherit</code>=== | ||
راية تحدد ما إذا كانت أسماء متغيرات الصنف في كل الوحدات المُضمّنة ستُشمل. | |||
==القيمة المُعادة== | ==القيمة المُعادة== | ||
يعيد التابع <code>class_variables</code> مصفوفة مكونة من أسماء متغيرات الصنف في الوحدة التي استُدعي معها. | |||
==أمثلة== | ==أمثلة== | ||
| سطر 24: | سطر 25: | ||
Two.class_variables(false) #=> [:@@var2]</syntaxhighlight> | Two.class_variables(false) #=> [:@@var2]</syntaxhighlight> | ||
==انظر أيضا== | ==انظر أيضا== | ||
* التابع <code>[[Ruby/Module/ | * التابع <code>[[Ruby/Module/class variable get|class_variable_get]]</code>: يعيد قيمة متغير الصنف المعطى (أو يطلق استثناء <code>NameError</code>). | ||
* التابع <code>[[Ruby/Module/ | |||
*التابع <code>[[Ruby/Module/class variable set|class_variable_set]]</code>: يضبط قيمة متغير الصنف المحدد بالوسيط <code>symbol</code> ويحيل إليه الكائن المعطى <code>obj</code>. | |||
*التابع <code>[[Ruby/Module/class variable defined-3F|class_variable_defined?]]</code>: يعيد القيمة <code>true</code> إن كان متغير الصنف (class variable) المعطى مٌعرّفا في obj. | |||
==مصادر== | ==مصادر== | ||
*[http://ruby-doc.org/core-2.5.1/Module.html#method-i-class_variables قسم التابع class_variables في الصنف Module في توثيق روبي الرسمي.] | *[http://ruby-doc.org/core-2.5.1/Module.html#method-i-class_variables قسم التابع class_variables في الصنف Module في توثيق روبي الرسمي.] | ||
مراجعة 22:15، 26 أكتوبر 2018
يعيد التابع class_variables مصفوفة مكونة من أسماء متغيرات الصنف في الوحدة التي استُدعي معها. يشمل ذلك أسماء متغيرات الصنف في كل الوحدات المُضمّنة، ما لم يتم تعيين الوسيط inherit عند القيمة false.
البنية العامة
class_variables(inherit=true) → array
المعاملات
inherit
راية تحدد ما إذا كانت أسماء متغيرات الصنف في كل الوحدات المُضمّنة ستُشمل.
القيمة المُعادة
يعيد التابع class_variables مصفوفة مكونة من أسماء متغيرات الصنف في الوحدة التي استُدعي معها.
أمثلة
مثال على استخدام التابع class_variables:
class One
@@var1 = 1
end
class Two < One
@@var2 = 2
end
One.class_variables #=> [:@@var1]
Two.class_variables #=> [:@@var2, :@@var1]
Two.class_variables(false) #=> [:@@var2]
انظر أيضا
- التابع
class_variable_get: يعيد قيمة متغير الصنف المعطى (أو يطلق استثناءNameError).
- التابع
class_variable_set: يضبط قيمة متغير الصنف المحدد بالوسيطsymbolويحيل إليه الكائن المعطىobj. - التابع
class_variable_defined?: يعيد القيمةtrueإن كان متغير الصنف (class variable) المعطى مٌعرّفا في obj.