Class: Proc

Inherits:
Object
  • Object
show all
Defined in:
lib/proc_source.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



160
161
162
# File 'lib/proc_source.rb', line 160

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



160
161
162
# File 'lib/proc_source.rb', line 160

def line
  @line
end

#sourceObject



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_descriptorObject



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