Module: ColorfulInspect
- Defined in:
- lib/colorful_inspect.rb
Class Attribute Summary collapse
-
.colors ⇒ Object
Returns the value of attribute colors.
-
.indent ⇒ Object
Returns the value of attribute indent.
Class Method Summary collapse
- .break(q) ⇒ Object
- .colorize(q, type, string) ⇒ Object
- .default_colors ⇒ Object
- .group(q, open, close, &block) ⇒ Object
- .method_info(method) ⇒ Object
Class Attribute Details
.colors ⇒ Object
Returns the value of attribute colors.
11 12 13 |
# File 'lib/colorful_inspect.rb', line 11 def colors @colors end |
.indent ⇒ Object
Returns the value of attribute indent.
10 11 12 |
# File 'lib/colorful_inspect.rb', line 10 def indent @indent end |
Class Method Details
.break(q) ⇒ Object
42 43 44 |
# File 'lib/colorful_inspect.rb', line 42 def break(q) q.text "\n#{q.genspace[q.indent]}" end |
.colorize(q, type, string) ⇒ Object
46 47 48 49 50 |
# File 'lib/colorful_inspect.rb', line 46 def colorize(q, type, string) Array(ColorfulInspect.colors[type]).inject(string) do |str, msg| Term::ANSIColor.send(msg, str) end end |
.default_colors ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/colorful_inspect.rb', line 15 def default_colors { :numeric => [:blue, :bold], :bignum => [:blue], :fixnum => [:blue, :bold], :float => [:blue, :bold], :rational => [:blue], :true => [:green, :bold], :false => [:red, :bold], :nil => [:red], :symbol => [:cyan, :bold], :string => [:green], :date => [:black], :time => [:black, :bold], :class => [:yellow, :bold], :module => [:yellow], :method => [:magenta], :exception => [:red], :ivar => [:cyan] } end |
.group(q, open, close, &block) ⇒ Object
37 38 39 40 |
# File 'lib/colorful_inspect.rb', line 37 def group(q, open, close, &block) q.group(ColorfulInspect.indent, open, "\n#{q.genspace[q.indent]}#{close}", &block) end |
.method_info(method) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/colorful_inspect.rb', line 52 def method_info(method) args = '' if method.respond_to?(:parameters) && (arg_ary = method.parameters) arg_ary.map!.each_with_index do |(type, name), index| name ||= "arg#{index + 1}" case type when :req then "#{name}" when :opt then "#{name} = ?" when :rest then "*#{name}" when :block then "&#{name}" else name end end args = '(' + arg_ary.join(', ') + ')' elsif method.arity == 0 args = "()" elsif method.arity > 0 n = method.arity args = '(' + (1..n).map { |i| "arg#{i}" }.join(", ") + ')' elsif method.arity < 0 n = -method.arity args = '(' + (1..n).map { |i| "arg#{i}" }.join(", ") + ')' end klass = if method.respond_to? :owner method.owner.to_s elsif method.inspect =~ /Method: (.*?)#/ $1 end location = if method.respond_to? :source_location file, line = method.source_location "#{file}:#{line}" if file && line end [method.name.to_s, args, klass.to_s, location] end |