D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Kernel
/
Filename :
binding-i.ri
back
Copy
U:RDoc::AnyMethod[iI"binding:ETI"Kernel#binding;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [ I";Returns a Binding object, describing the variable and ;TI"Hmethod bindings at the point of call. This object can be used when ;TI"Ccalling Binding#eval to execute the evaluated command in this ;TI"4environment, or extracting its local variables.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"class User ;TI"& def initialize(name, position) ;TI" @name = name ;TI" @position = position ;TI" end ;TI" ;TI" def get_binding ;TI" binding ;TI" end ;TI" end ;TI" ;TI"(user = User.new('Joan', 'manager') ;TI"5template = '{name: @name, position: @position}' ;TI" ;TI"2# evaluate template in context of the object ;TI"&eval(template, user.get_binding) ;TI"/#=> {:name=>"Joan", :position=>"manager"} ;T:@format0o; ; [I"DBinding#local_variable_get can be used to access the variables ;TI",whose names are reserved Ruby keywords:;T@o;; [I"E# This is valid parameter declaration, but `if` parameter can't ;TI";# be accessed by name, because it is a reserved word. ;TI".def validate(field, validation, if: nil) ;TI"4 condition = binding.local_variable_get('if') ;TI" return unless condition ;TI" ;TI"$ # ...Some implementation ... ;TI" end ;TI" ;TI"<validate(:name, :empty?, if: false) # skips validation ;TI"=validate(:name, :empty?, if: true) # performs validation;T; 0: @fileI"proc.c;T:0@omit_headings_from_table_of_contents_below0I"binding -> a_binding ;T0[ I"();T@6FI"Kernel;TcRDoc::NormalModule00