Class: Proc
- Inherits:
-
Object
- Object
- Proc
- Defined in:
- lib/proc_source.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
- #source ⇒ Object
Class Method Summary collapse
-
.from_string(str) ⇒ Object
Create a Proc object from a string of Ruby code.
Instance Method Summary collapse
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
160 161 162 |
# File 'lib/proc_source.rb', line 160 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
160 161 162 |
# File 'lib/proc_source.rb', line 160 def line @line end |
#source ⇒ Object
172 173 174 |
# File 'lib/proc_source.rb', line 172 def source @source ||= ProcSource.find(*self.source_descriptor) end |
Class Method Details
.from_string(str) ⇒ Object
Create a Proc object from a string of Ruby code. It’s assumed the string contains do; end or { }.
Proc.from_string("do; 2+2; end")
181 182 183 |
# File 'lib/proc_source.rb', line 181 def self.from_string(str) eval "Proc.new #{str}" end |
Instance Method Details
#source_descriptor ⇒ Object
163 164 165 166 167 168 169 170 |
# File 'lib/proc_source.rb', line 163 def source_descriptor unless @file && @line if md = /^#<Proc:0x[0-9A-Fa-f]+@(.+):(\d+)(.+?)?>$/.match(inspect) @file, @line = md.captures end end [@file, @line.to_i] end |