الفرق بين المراجعتين لصفحة: «Ruby/Binding»
ط نقل محمد-بغات صفحة Binding إلى Ruby/Binding |
لا ملخص تعديل |
||
| سطر 24: | سطر 24: | ||
== التوابع العامة (Public Instance Methods) == | == التوابع العامة (Public Instance Methods) == | ||
===[[Ruby/Binding/eval | التابع <code>Binding.eval</code> ]]=== | ===[[Ruby/Binding/eval | التابع <code>Binding.eval</code>]]=== | ||
يقدر التابع <code>eval</code> تعابير لغة روبي الممررة إليه في السياق <code>binding</code>. في حال تمرير الوسيطين الاختياريين <code>filename</code> و <code>lineno</code>، فسيُستخدمان عند الإبلاغ عن وجود أخطاء في الصياغة ( | يقدر التابع <code>eval</code> تعابير لغة روبي الممررة إليه في السياق <code>binding</code>. في حال تمرير الوسيطين الاختياريين <code>filename</code> و <code>lineno</code>، فسيُستخدمان عند الإبلاغ عن وجود أخطاء في الصياغة (syntax errors). | ||
===[[Ruby/Binding/local_variables | <code> | ===[[Ruby/Binding/local_variables |<code>التابع Binding.local_variables</code>]]=== | ||
يعيد التابع <code>local_variables</code> أسماء المتغيرات المحلية المعرفة في <code>Binding</code> على شكل رموز ( | يعيد التابع <code>local_variables</code> أسماء المتغيرات المحلية المعرفة في <code>Binding</code> على شكل رموز (symbols). | ||
===[[Ruby/Binding/local_variable_defined-3F |<code>التابع Binding.local_variable_defined?</code>]] === | |||
يتحقق التابع <code>local_variable_defined?</code> إن كان المتغير <code>symbol</code> المحلي موجودًا أم لا. | |||
===[[Ruby/Binding/local_variable_defined-3F | <code> | ===[[Ruby/Binding/local_variable_get |<code>التابع Binding.local_variable_get</code>]]=== | ||
يتحقق التابع | |||
===[[Ruby/Binding/local_variable_get | <code> | |||
يعيد التابع<code>local_variable_get</code> قيمة المتغير المحلي الممرَّر إليه. | يعيد التابع<code>local_variable_get</code> قيمة المتغير المحلي الممرَّر إليه. | ||
===[[Ruby/Binding/local_variable_set |<code>التابع Binding.local_variable_set</code>]]=== | |||
===[[Ruby/Binding/local_variable_set | <code> | |||
يضبط التابع <code>local_variable_set</code> قيمة المتغير المحلي الممرر إليه إلى قيمة معينة. | يضبط التابع <code>local_variable_set</code> قيمة المتغير المحلي الممرر إليه إلى قيمة معينة. | ||
===[[Ruby/Binding/receiver |<code>التابع Binding.receiver</code>]]=== | |||
يعيد التابع <code>receiver</code> المستقبِل المرتبط (bound receiver) لكائن الربط (binding object). | |||
===[[Ruby/Binding/receiver | <code> | |||
يعيد التابع <code>receiver</code> المستقبِل المرتبط ( | |||
== مصادر == | == مصادر == | ||
صفحة الصنف Binding في توثيق روبي الرسمي. | [http://ruby-doc.org/core-2.5.1/Binding.html صفحة الصنف Binding في توثيق روبي الرسمي.] | ||
مراجعة 13:11، 12 سبتمبر 2018
تُغلِّف كائنات الصنف Binding سياق التنفيذ (execution context) في مكان معين في الشيفرة البرمجية، وتحتفظ بذلك السياق لاستخدامه مستقبلًا. يُحتفَظ بالمتغيرات، والتوابع، وقيمة self، وربما كتلة المكرر (iterator block) وكل ما يمكن الوصول إليه في هذا السياق. يمكن إنشاء كائنات الصنف Binding باستخدام التابع Kernel.binding، واستدعاؤها بوساطة التابع Kernel.set_trace_func.
يمكن تمرير كائنات الربط (binding objects) هذه كوسيط ثانٍ للتابع Kernel.eval لإنشاء بيئة للتقييم (evaluation).
class Demo
def initialize(n)
@secret = n
end
def get_binding
binding
end
end
k1 = Demo.new(99)
b1 = k1.get_binding
k2 = Demo.new(-3)
b2 = k2.get_binding
eval("@secret", b1) #=> 99
eval("@secret", b2) #=> -3
eval("@secret") #=> nil
التوابع العامة (Public Instance Methods)
التابع Binding.eval
يقدر التابع eval تعابير لغة روبي الممررة إليه في السياق binding. في حال تمرير الوسيطين الاختياريين filename و lineno، فسيُستخدمان عند الإبلاغ عن وجود أخطاء في الصياغة (syntax errors).
التابع Binding.local_variables
يعيد التابع local_variables أسماء المتغيرات المحلية المعرفة في Binding على شكل رموز (symbols).
التابع Binding.local_variable_defined?
يتحقق التابع local_variable_defined? إن كان المتغير symbol المحلي موجودًا أم لا.
التابع Binding.local_variable_get
يعيد التابعlocal_variable_get قيمة المتغير المحلي الممرَّر إليه.
التابع Binding.local_variable_set
يضبط التابع local_variable_set قيمة المتغير المحلي الممرر إليه إلى قيمة معينة.
التابع Binding.receiver
يعيد التابع receiver المستقبِل المرتبط (bound receiver) لكائن الربط (binding object).