Guest User

Untitled

a guest
Feb 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. # Enable tab-completion.
  2. require 'irb/completion'
  3.  
  4. # Auto-indentation.
  5. IRB.conf[:AUTO_INDENT] = true
  6.  
  7. # local_methods shows methods that are only available for a given object.
  8. class Object
  9. def local_methods
  10. self.methods.sort - self.class.superclass.methods
  11. end
  12. end
  13.  
  14. # Dynamic method finding; e.g., "hello".what? == 5 #=> ["length", "size"]
  15. begin
  16. require 'rubygems'
  17. require 'what_methods'
  18. rescue LoadError
  19. puts "Error loading method_finder. Run 'sudo gem install what_methods' to enable Object#what? method finding."
  20. end
  21.  
  22. # Colorize results
  23. begin
  24. require 'rubygems'
  25. require 'wirble'
  26. Wirble.init
  27. Wirble::Colorize.colors.merge!({:comma => :light_purple, :refers => :red, :object_addr_prefix => :brown, :object_line_prefix => :brown, :object_class => :green, :string => :light_gray})
  28. Wirble.colorize
  29. rescue LoadError
  30. puts "Error loading Wirble. Run 'sudo gem install wirble' to enable colorized results."
  31. end
  32.  
  33. # Inline colorized ri (override wirble's)
  34. RIARGS = ['-f', 'ansi']
  35. require 'rdoc/ri/ri_driver'
  36. class MyStupidRiDriver < RiDriver
  37. def self.ri(*topics)
  38. topics.map! { |topic| topic.to_s }
  39. begin
  40. MyStupidRiDriver.new(*topics).process_args
  41. rescue => e
  42. puts "Error processing ri request: #{e}"
  43. end
  44. end
  45.  
  46. def initialize(*topics)
  47. @options = RI::Options.instance
  48. args = RIARGS.dup + topics
  49. @options.parse(args)
  50. paths = RI::Paths::PATH
  51. @ri_reader = RI::RiReader.new(RI::RiCache.new(paths))
  52. @display = @options.displayer
  53. end
  54. end
  55.  
  56. def Kernel.ri(*args)
  57. less { MyStupidRiDriver.ri(*args) }
  58. end
  59.  
  60. class Module
  61. def ri(*args)
  62. topics = args.map { |arg| arg = "#{self}##{arg}" }
  63. less { MyStupidRiDriver.ri(*topics) }
  64. end
  65. end
  66.  
  67. # Copious output helper
  68. def less
  69. spool_output('less')
  70. end
  71.  
  72. def most
  73. spool_output('most')
  74. end
  75.  
  76. def spool_output(spool_cmd)
  77. require 'stringio'
  78. $stdout, sout = StringIO.new, $stdout
  79. yield
  80. $stdout, str_io = sout, $stdout
  81. IO.popen(spool_cmd, 'w') do |f|
  82. f.write str_io.string
  83. f.flush
  84. f.close_write
  85. end
  86. end
  87.  
  88. # Simple regular expression helper
  89. # show_regexp - stolen from the pickaxe
  90. def show_regexp(a, re)
  91. if a =~ re
  92. "#{$`}<<#{$&}>>#{$'}"
  93. else
  94. "no match"
  95. end
  96. end
  97.  
  98. # Convenience method on Regexp so you can do
  99. # /an/.show_match("banana")
  100. class Regexp
  101. def show_match(a)
  102. show_regexp(a, self)
  103. end
  104. end
  105.  
  106. # Textmate helper
  107. def mate *args
  108. flattened_args = args.map {|arg| "\"#{arg.to_s}\""}.join ' '
  109. `mate #{flattened_args}`
  110. nil
  111. end
  112.  
  113. # Vi helper
  114. def vi *args
  115. flattened_args = args.map { |arg| "\"#{arg.to_s}\""}.join ' '
  116. `vi #{flattened_args}`
  117. nil
  118. end
Add Comment
Please, Sign In to add comment