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

من موسوعة حسوب
< Ruby‏ | Kernel
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع <code>test‎</code> الخاص بالصنف <code>Kernel</code> في روبي}}</noinclude> تصنيف: Ruby تصنيف...')
 
سطر 3: سطر 3:
 
[[تصنيف: Ruby Method]]
 
[[تصنيف: Ruby Method]]
 
[[تصنيف: Ruby Kernel]]
 
[[تصنيف: Ruby Kernel]]
يستخدم التابع test الحرف <code>cmd</code> لإجراء عدة اختبارات على <code>file1</code> (الجدول الأول أدناه) أو على <code>file1</code> و <code>file2</code> (الجدول الثاني).
+
يستخدم التابع <code>test</code> الحرف المٌعطى <code>cmd</code> لإجراء عدة اختبارات على <code>file1</code> (الجدول الأول أدناه) أو على <code>file1</code> و <code>file2</code> (الجدول الثاني).
 
اختبارات <code>File</code> على ملف واحد:
 
اختبارات <code>File</code> على ملف واحد:
<syntaxhighlight lang="ruby">Cmd   Returns   Meaning
+
{| class="wikitable"
"A" | Time    | Last access time for file1
+
!Cmd   
"b" | boolean | True if file1 is a block device
+
!يعيد
"c" | boolean | True if file1 is a character device
+
!شرح
"C" | Time   | Last change time for file1
+
|-
"d" | boolean | True if file1 exists and is a directory
+
|<code>"A"</code>
"e" | boolean | True if file1 exists
+
|Time     
"f" | boolean | True if file1 exists and is a regular file
+
|توقيت آخر دخول إلى <code>file1</code>
"g" | boolean | True if file1 has the \CF{setgid} bit
+
|-
    |        | set (false under NT)
+
|<code>"b"</code>
"G" | boolean | True if file1 exists and has a group
+
|قيمة منطقية
    |         | ownership equal to the caller's group
+
|يعيد <code>True</code> إن كان <code>file1</code> من النوع block device
"k" | boolean | True if file1 exists and has the sticky bit set
+
|-
"l" | boolean | True if file1 exists and is a symbolic link
+
|<code>"c"</code>
"M" | Time   | Last modification time for file1
+
|قيمة منطقية
"o" | boolean | True if file1 exists and is owned by
+
|يعيد <code>True</code> إن كان <code>file1</code> من النوع character device
    |        | the caller's effective uid
+
|-
"O" | boolean | True if file1 exists and is owned by
+
|<code>"C"</code>
    |        | the caller's real uid
+
|Time
"p" | boolean | True if file1 exists and is a fifo
+
|توقيت آخر تغيير في <code>file1</code>
"r" | boolean | True if file1 is readable by the effective
+
|-
    |        | uid/gid of the caller
+
|<code>"d"</code>
"R" | boolean | True if file is readable by the real
+
|قيمة منطقية
    |        | uid/gid of the caller
+
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكان مجلدًا
"s" | int/nil | If file1 has nonzero size, return the size,
+
|-
    |         | otherwise return nil
+
|<code>"e"</code>
"S" | boolean | True if file1 exists and is a socket
+
|قيمة منطقية
"u" | boolean | True if file1 has the setuid bit set
+
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا
"w" | boolean | True if file1 exists and is writable by
+
|-
    |        | the effective uid/gid
+
|<code>"f"</code>
"W" | boolean | True if file1 exists and is writable by
+
|قيمة منطقية
    |        | the real uid/gid
+
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكان ملفا عاديا
"x" | boolean | True if file1 exists and is executable by
+
|-
    |        | the effective uid/gid
+
|<code>"g"</code>
"X" | boolean | True if file1 exists and is executable by
+
|قيمة منطقية
    |        | the real uid/gid
+
|يعيد <code>True</code>إن كانت البتة‎ <code>\CF{setgid}</code>‎الخاصة بـ<code>file1</code>  مُعيّنة (ليست معينة في NT)،
"z" | boolean | True if file1 exists and has a zero length‎</syntaxhighlight>
+
|-
اختبارات تشمل ملفين:
+
|<code>"G"</code>
<syntaxhighlight lang="ruby">"-" | boolean | True if file1 and file2 are identical
+
|قيمة منطقية
"=" | boolean | True if the modification times of file1
+
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكانت مجموعته مساوية لمجموعة المُُستدعي.
    |         | and file2 are equal
+
|-
"<" | boolean | True if the modification time of file1
+
|<code>"k"</code>
    |         | is prior to that of file2
+
|قيمة منطقية
">" | boolean | True if the modification time of file1
+
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكانت البتة اللزجة (sticky bit) مُعيّنة.
    |        | is after that of file2‎</syntaxhighlight>
+
|-
 +
|<code>"l"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكان رابطا رمزيا (symbolic link).
 +
|-
 +
|<code>"M"</code>
 +
|Time
 +
|توقيت آخر تعديل على <code>file1</code>
 +
|-
 +
|<code>"o"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكان مملوكا المعرف العملي للمُستدعي (caller's effective uid).
 +
|-
 +
|<code>"O"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكان مملوكا المعرف الحقيقي للمُستدعي (caller's real uid).
 +
|-
 +
|<code>"p"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكان من النوع fifo
 +
|-
 +
|<code>"r"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> قابلا للقراءة من المعرف العملي للمُستدعي (effective uid/gid of the caller).
 +
|-
 +
|<code>"R"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> قابلا للقراءة من المعرف الحقيقي للمُستدعي (real uid/gid of the caller).
 +
|-
 +
|<code>"s"</code>
 +
|int/nil
 +
|إن كان حجم <code>file1</code> غير معدوم، فسيعيد الحجم، أو سيعيد <code>nil</code>.
 +
|-
 +
|<code>"S"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وكان من النوع socket
 +
|-
 +
|<code>"u"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code>إن كانت البتة‎ <code>setuid</code> ‎الخاصة بـ<code>file1</code>  مُعيّنة
 +
|-
 +
|<code>"w"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> قابلا للكتابة من المعرف العملي للمُستدعي (effective uid/gid of the caller).
 +
|-
 +
|<code>"W"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> قابلا للكتابة من المعرف الحقيقي للمُستدعي (real uid/gid of the caller).
 +
|-
 +
|<code>"x"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> قابلا للتنفيذ من المعرف العملي للمُستدعي (effective uid/gid of the caller).
 +
|-
 +
|<code>"X"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> قابلا للتنفيذ من المعرف الحقيقي للمُستدعي (real uid/gid of the caller).
 +
|-
 +
|<code>"z"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> موجودًا وطوله غير معدوم
 +
|}
 +
الاختبارات التي تشمل ملفين:
 +
{| class="wikitable"
 +
|<code>"-"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان <code>file1</code> و <code>file2</code> متطابقين.
 +
|-
 +
|<code>"="</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان توقيت تعديل <code>file1</code> و <code>file2</code> متساويين.
 +
|-
 +
|<code>"<"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان توقيت تعديل <code>file1</code> قبل توقيت تعديل <code>file2</code>.
 +
|-
 +
|<code>">"</code>
 +
|قيمة منطقية
 +
|يعيد <code>True</code> إن كان توقيت تعديل <code>file1</code> بعد توقيت تعديل<code>file2</code>.
 +
|}
 +
 
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="ruby">test(cmd, file1 [, file2] ) → obj‎</syntaxhighlight>
 
<syntaxhighlight lang="ruby">test(cmd, file1 [, file2] ) → obj‎</syntaxhighlight>
 
==المعاملات==
 
==المعاملات==
 
===<code>cmd‎</code>===
 
===<code>cmd‎</code>===
 +
يحدد الخيارات.
  
 
===<code>file1‎</code>===
 
===<code>file1‎</code>===
 +
الملف الأول.
  
 
===<code>file2‎</code>===
 
===<code>file2‎</code>===
  
 
+
الملف الثاني.
 
==القيمة المُعادة==
 
==القيمة المُعادة==
 +
يعيد كائنا بحسب قيمة الوسيط <code>cmd‎</code> (انظر الجدولين أعلاه).
  
 
==انظر أيضا==
 
==انظر أيضا==
* التابع <code>[[Ruby/Kernel/system|system]]</code>: ينفذ التابع system الوسيط command… في صدفة فرعية (subshell).يأخذ command… أحد الأشكال التالية.
+
* التابع <code>[[Ruby/Kernel/system|system]]</code>: ينفذ التابع system الوسيط المعطى في صدفة فرعية (subshell).
* التابع <code>[[Ruby/Kernel/throw|throw]]</code>: ينقل التابع throw الضبط (control) إلى نهاية كتلة <code>catch</code> النشطة في انتظار الوسم (tag). ويطلق <code>UncaughtThrowError</code> إذا لم يكن هناك كتلة <code>catch</code> لذلك الوسم. يوفر الوسيط الاختياري الثاني قيمة لتُعيدها الكتلة <code>catch</code>، في حال عدم تمريره ستكون قيمتها الافتراضية هي <code>nil</code>. للحصول على بعض الأمثلة، انظر <code>Kernel::catch</code>.
 
  
 
==مصادر==
 
==مصادر==
 
*[http://ruby-doc.org/core-2.5.1/Kernel.html#method-i-test قسم  التابع test‎ في الصنف Kernel‎ في توثيق روبي الرسمي.]
 
*[http://ruby-doc.org/core-2.5.1/Kernel.html#method-i-test قسم  التابع test‎ في الصنف Kernel‎ في توثيق روبي الرسمي.]

مراجعة 23:31، 23 أكتوبر 2018

يستخدم التابع test الحرف المٌعطى cmd لإجراء عدة اختبارات على file1 (الجدول الأول أدناه) أو على file1 و file2 (الجدول الثاني). اختبارات File على ملف واحد:

Cmd يعيد شرح
"A" Time توقيت آخر دخول إلى file1
"b" قيمة منطقية يعيد True إن كان file1 من النوع block device
"c" قيمة منطقية يعيد True إن كان file1 من النوع character device
"C" Time توقيت آخر تغيير في file1
"d" قيمة منطقية يعيد True إن كان file1 موجودًا وكان مجلدًا
"e" قيمة منطقية يعيد True إن كان file1 موجودًا
"f" قيمة منطقية يعيد True إن كان file1 موجودًا وكان ملفا عاديا
"g" قيمة منطقية يعيد Trueإن كانت البتة‎ \CF{setgid}‎الخاصة بـfile1 مُعيّنة (ليست معينة في NT)،
"G" قيمة منطقية يعيد True إن كان file1 موجودًا وكانت مجموعته مساوية لمجموعة المُُستدعي.
"k" قيمة منطقية يعيد True إن كان file1 موجودًا وكانت البتة اللزجة (sticky bit) مُعيّنة.
"l" قيمة منطقية يعيد True إن كان file1 موجودًا وكان رابطا رمزيا (symbolic link).
"M" Time توقيت آخر تعديل على file1
"o" قيمة منطقية يعيد True إن كان file1 موجودًا وكان مملوكا المعرف العملي للمُستدعي (caller's effective uid).
"O" قيمة منطقية يعيد True إن كان file1 موجودًا وكان مملوكا المعرف الحقيقي للمُستدعي (caller's real uid).
"p" قيمة منطقية يعيد True إن كان file1 موجودًا وكان من النوع fifo
"r" قيمة منطقية يعيد True إن كان file1 قابلا للقراءة من المعرف العملي للمُستدعي (effective uid/gid of the caller).
"R" قيمة منطقية يعيد True إن كان file1 قابلا للقراءة من المعرف الحقيقي للمُستدعي (real uid/gid of the caller).
"s" int/nil إن كان حجم file1 غير معدوم، فسيعيد الحجم، أو سيعيد nil.
"S" قيمة منطقية يعيد True إن كان file1 موجودًا وكان من النوع socket
"u" قيمة منطقية يعيد Trueإن كانت البتة‎ setuid ‎الخاصة بـfile1 مُعيّنة
"w" قيمة منطقية يعيد True إن كان file1 قابلا للكتابة من المعرف العملي للمُستدعي (effective uid/gid of the caller).
"W" قيمة منطقية يعيد True إن كان file1 قابلا للكتابة من المعرف الحقيقي للمُستدعي (real uid/gid of the caller).
"x" قيمة منطقية يعيد True إن كان file1 قابلا للتنفيذ من المعرف العملي للمُستدعي (effective uid/gid of the caller).
"X" قيمة منطقية يعيد True إن كان file1 قابلا للتنفيذ من المعرف الحقيقي للمُستدعي (real uid/gid of the caller).
"z" قيمة منطقية يعيد True إن كان file1 موجودًا وطوله غير معدوم

الاختبارات التي تشمل ملفين:

"-" قيمة منطقية يعيد True إن كان file1 و file2 متطابقين.
"=" قيمة منطقية يعيد True إن كان توقيت تعديل file1 و file2 متساويين.
"<" قيمة منطقية يعيد True إن كان توقيت تعديل file1 قبل توقيت تعديل file2.
">" قيمة منطقية يعيد True إن كان توقيت تعديل file1 بعد توقيت تعديلfile2.

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

test(cmd, file1 [, file2] )  obj

المعاملات

cmd‎

يحدد الخيارات.

file1‎

الملف الأول.

file2‎

الملف الثاني.

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

يعيد كائنا بحسب قيمة الوسيط cmd‎ (انظر الجدولين أعلاه).

انظر أيضا

  • التابع system: ينفذ التابع system الوسيط المعطى في صدفة فرعية (subshell).

مصادر