Sha256: 3e9d0d831df4cc4acec1164c7f787650dc2a56bc268c54323a7ffd0ac89ce462

Contents?: true

Size: 627 Bytes

Versions: 8

Compression:

Stored size: 627 Bytes

Contents

# frozen_string_literal: true

require 'pry'
require 'pry-disasm/commands'

class PryDisasm
  def self.process(expr)
    str = RubyVM::InstructionSequence.disasm(expr)

    lines = str.split("\n")
    lines[0].gsub!(/=+/) { |s| "\033[0;32m#{s}\033[0m" }
    lines[0].gsub!(/<(.*?)@(.*?)>/) { "<\033[0;33m#{$1}\033[0m@\033[0;33m#{$2}\033[0m>" }

    (1..lines.length).each do |i|
      lines[i] = "\033[0;35m#{lines[i]}\033[0m"
      lines[i].gsub!(/^(.*?)(\s+)(.*?)(\s+)/) { "#{$1}#{$2}\033[0;36m#{$3}\033[0m#{$4}" }
      lines[i].gsub!(/<(.*?):(.*?)>/) { "<\033[0;34m#{$1}\033[0m#:#{$2}>" }
    end

    puts lines
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pryx-0.4.4 lib/pry-disasm.rb
pryx-0.4.3 lib/pry-disasm.rb
pryx-0.4.2 lib/pry-disasm.rb
pryx-0.4.1 lib/pry-disasm.rb
pryx-0.4.0 lib/pry-disasm.rb
pryx-0.3.1 lib/pry-disasm.rb
pryx-0.3.0 lib/pry-disasm.rb
pryx-0.2.2 lib/pry-disasm.rb