Class: IRB::PaCommand

Inherits:
Command::Base
  • Object
show all
Defined in:
lib/irb/cmd/pa.rb

Instance Method Summary collapse

Instance Method Details

#execute(expression) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/irb/cmd/pa.rb', line 20

def execute(expression)
  if expression == ''
    # Avoid warn and raise here, warn does not appear in irb and exception sounds like a IRB bug
    puts usage
    return
  end

  result = nil
  inspection = nil
  ::PowerAssert.start(expression, source_binding: irb_context.workspace.binding) do |pa|
    result = pa.yield
    inspection = pa.message_proc.call
  end

  if inspection == ''
    puts usage
  else
    puts inspection, "\n"
  end

  puts "=> #{result.inspect}"
end

#usageObject



13
14
15
16
17
18
# File 'lib/irb/cmd/pa.rb', line 13

def usage
  <<~'EOD'
    `pa` command will work for expressions that includes method calling.
    e.g. `pa (2 * 3 * 7).abs == 1010102.to_s.to_i(2)`
  EOD
end