class Irbtools::Command::Howtocall

Public Instance Methods

execute(arg) click to toggle source
# File lib/irbtools/commands/howtocall.rb, line 35
def execute(arg)
  if howtocall_parameters_code = transform_arg(arg)
    howtocall_parameters = @irb_context.workspace.binding.eval(howtocall_parameters_code)
    @irb_context.workspace.binding.send(:howtocall, *howtocall_parameters)
  else
    warn "howtocall: Please use rdoc syntax, e.g. Array#sum"
  end
rescue NameError
  warn "howtocall: Class or method not found"
end
transform_arg(arg) click to toggle source
# File lib/irbtools/commands/howtocall.rb, line 17
def transform_arg(arg)
  if arg.empty?
    "[]"
  elsif arg.strip =~ /\A(?:([\w:]+)([#.]))?(\w+[?!]?)\z/
    if $1
      if $2 == "#"
        "[#{$1}, #{$1}.instance_method(:#{$3})]"
      else
        "[#{$1}, :#{$3}]"
      end
    else
      "[:#{$3}]"
    end
  else
    nil
  end
end