Class: Proc

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



143
144
145
# File 'lib/proc_source.rb', line 143

def source
  @source
end

Class Method Details

._load(code) ⇒ Object



187
188
189
# File 'lib/proc_source.rb', line 187

def self._load(code)
  self.from_string(code)
end

.allocateObject



179
# File 'lib/proc_source.rb', line 179

def self.allocate; from_string ""; end

.from_string(string) ⇒ Object



181
182
183
184
185
# File 'lib/proc_source.rb', line 181

def self.from_string(string)
  result = eval("proc {#{string}}")
  result.source = string
  return result
end

.marshal_loadObject



191
# File 'lib/proc_source.rb', line 191

def self.marshal_load; end

Instance Method Details

#==(other) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/proc_source.rb', line 158

def ==(other)
  if self.source and other.source
    self.source == other.source
  else
    self.object_id == other.object_id
  end
end

#_dump(depth = 0) ⇒ Object



166
167
168
169
170
171
172
# File 'lib/proc_source.rb', line 166

def _dump(depth = 0)
  if source
    source
  else
    raise(TypeError, "Can't serialize Proc with unknown source code.")
  end
end

#inspectObject



150
151
152
153
154
155
156
# File 'lib/proc_source.rb', line 150

def inspect
  if source
    "proc {#{source}}"
  else
    old_inspect
  end
end

#marshal_loadObject



192
# File 'lib/proc_source.rb', line 192

def marshal_load; end

#old_inspectObject



149
# File 'lib/proc_source.rb', line 149

alias :old_inspect :inspect

#source_descriptorObject



136
137
138
139
140
141
# File 'lib/proc_source.rb', line 136

def source_descriptor
  if md = /^#<Proc:0x[0-9A-Fa-f]+@(.+):(\d+)>$/.match(old_inspect)
    filename, line = md.captures
    return filename, line.to_i
  end
end

#to_yaml(*args) ⇒ Object



174
175
176
177
# File 'lib/proc_source.rb', line 174

def to_yaml(*args)
  self.source # force @source to be set
  super.sub("object:Proc", "proc")
end