Class: Proc
- Inherits:
-
Object
- Object
- Proc
- Defined in:
- lib/proc_source.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #_dump(depth = 0) ⇒ Object
- #inspect ⇒ Object
- #marshal_load ⇒ Object
- #old_inspect ⇒ Object
- #source_descriptor ⇒ Object
- #to_yaml(*args) ⇒ Object
Instance Attribute Details
#source ⇒ Object
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 |
.allocate ⇒ Object
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_load ⇒ Object
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 |
#inspect ⇒ Object
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_load ⇒ Object
192 |
# File 'lib/proc_source.rb', line 192 def marshal_load; end |
#old_inspect ⇒ Object
149 |
# File 'lib/proc_source.rb', line 149 alias :old_inspect :inspect |
#source_descriptor ⇒ Object
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 |