Sha256: c5eb6f5d3340e8ae9104119001a32bc050f642730e8a3fe7150043294051d234

Contents?: true

Size: 751 Bytes

Versions: 2

Compression:

Stored size: 751 Bytes

Contents

module TablePrint
  module Printable
    # Sniff the data class for non-standard methods to use as a baseline for display
    def self.default_display_methods(target)
      return target.class.columns.collect(&:name) if target.class.respond_to? :columns
      
      return target.keys if target.is_a? Hash
      return target.members.collect(&:to_sym) if target.is_a? Struct
      
      methods = []
      target.methods.each do |method_name|
        method = target.method(method_name)

        if method.owner == target.class
          if method.arity == 0 #
            methods << method_name.to_s
          end
        end
      end

      methods.delete_if { |m| m[-1].chr == "!" } # don't use dangerous methods
      methods
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
table_print-1.4.1 lib/table_print/printable.rb
table_print-1.4.0 lib/table_print/printable.rb