Flowdock
method

code_around_binding

Importance_0
v2_5_5 - Show latest stable - 0 notes - Class: IRB::WorkSpace
code_around_binding() public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

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
Register or log in to add new notes.