Module: FastRI::Util::MagicHelp

Defined in:
lib/fastri/util.rb

Instance Method Summary collapse

Instance Method Details

#help_method_extract(m) ⇒ Object

:nodoc:



131
132
133
134
135
136
# File 'lib/fastri/util.rb', line 131

def help_method_extract(m) # :nodoc:
  unless m.inspect =~ %r[\A#<(?:Unbound)?Method: (.*?)>\Z]
    raise "Cannot parse result of #{m.class}#inspect: #{m.inspect}"
  end
  $1.sub(/\A.*?\((.*?)\)(.*)\Z/){ "#{$1}#{$2}" }.sub(/\./, "::").sub(/#<Class:(.*?)>#/) { "#{$1}::" }
end

#magic_help(query) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/fastri/util.rb', line 138

def magic_help(query)
  if query =~ /\A(.*?)(#|::|\.)([^:#.]+)\Z/
    c, k, m = $1, $2, $3
    mid = m
    begin
      c = c.split(/::/).inject(Object){|s,x| s.const_get(x)}
      m = case k
          when "#"
            c.instance_method(m)
          when "::"
            c.method(m)
          when "."
            begin
              # if it's a private_instance_method, assume it was created
              # with module_function
              if c.private_instance_methods.include?(m)
                c.instance_method(m)
              else
                c.method(m)
              end
            rescue NameError
              c.instance_method(m)
            end
          end

      ret = help_method_extract(m)
      if ret == 'Class#new' and
          c.private_method_defined?(:initialize)
        return c.name + "::new"
      elsif ret =~ /^Kernel#/ and
          Kernel.instance_methods(false).include? mid
        return "Object##{mid}"
      end
      ret
    rescue Exception
      query
    end
  else
    query
  end
end