method
code_around_binding
v2_5_5 -
Show latest stable
-
0 notes -
Class: IRB::WorkSpace
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10
- 2_2_9
- 2_4_6
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
code_around_binding()
public
Hide source
# File lib/irb/workspace.rb, line 110 def code_around_binding file, pos = @binding.eval('[__FILE__, __LINE__]') unless defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file] begin lines = File.readlines(file) rescue SystemCallError return end end pos -= 1 start_pos = [pos - 5, 0].max end_pos = [pos + 5, lines.size - 1].min fmt = " %2s %#{end_pos.to_s.length}d: %s" body = (start_pos..end_pos).map do |current_pos| sprintf(fmt, pos == current_pos ? '=>' : '', current_pos + 1, lines[current_pos]) end.join("") "\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}\n" end