Sha256: cae58c686b2e19dcf43104825c800fdc9ea068536e72aa4fbe8754819bf065dd

Contents?: true

Size: 1.64 KB

Versions: 8

Compression:

Stored size: 1.64 KB

Contents

require_rel 'method_desc'
class Class
  # just runs ri against the class, outputs a big
  def desc_class options = {}
    # want_output = false, verbose = false
    begin
      puts "begin RI"
      RDoc::RI::Driver.run [to_s, '--no-pager']
      puts 'end ri'
    rescue SystemExit
      # not found
    end

    class_methods = methods(false)
    for ancestor in ancestors[1..-1] # skip the first one, which is yourself
      class_methods -= ancestor.methods(false)
    end

    doc = []
    doc << to_s
    doc += ["non inherited methods:", instance_methods(false).sort.join(", ")]
    doc += ['non inherited class methods:', class_methods.sort.join(', ')]
    doc += ["ancestors:", ancestors.join(', ')] if options[:verbose]
    doc += ["Constants (possible sub classes):",  constants.join(', ')] if constants.length > 0 && options[:verbose]
    puts doc
    doc if options[:want_output]
  end

end

=begin
doctest:

it should return true if you run it against a "real" class
>> String.desc_class(:want_output => true).length > 1
=> true
>> class A; end
>> A.desc_class(:want_output => true).length > 1
=>  true

it shouldn't report itself as an ancestor of itself
>> A.desc_class(:want_output => true).grep(/ancestors/).include? '[A]'
=> false

also lists constants
>> A.desc_class(:want_output => true, :verbose => true).grep(/constants/i)
=> [] # should be none since we didn't add any constants to A
>> class A; B = 3; end
>> A.desc_class(:want_output => true, :verbose => true).grep(/constants/i).length
=> 1 # should be none since we didn't add any constants to A

should work with sub methods
>> String.desc_method(:strip)

doctest_require: '../method_desc'
=end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
rogerdpack-desc_method-0.1.2 lib/method_describer/class_desc.rb
rogerdpack-desc_method-0.1.3 lib/method_describer/class_desc.rb
rogerdpack-desc_method-0.1.4 lib/method_describer/class_desc.rb
rogerdpack-desc_method-0.1.5 lib/method_describer/class_desc.rb
desc_method-0.1.8 lib/method_describer/class_desc.rb
desc_method-0.1.7 lib/method_describer/class_desc.rb
desc_method-0.1.6 lib/method_describer/class_desc.rb
desc_method-0.1.5 lib/method_describer/class_desc.rb