Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 85 lines (72 sloc) 2.553 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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
require 'looksee/adapter/base'
require 'looksee/rbx'

module Looksee
  module Adapter
    class Rubinius < Base
      def internal_superclass(klass)
        klass.direct_superclass
      end

      def internal_public_instance_methods(mod)
        return [] if !mod.origin.equal?(mod)
        mod.method_table.public_names
      end

      def internal_protected_instance_methods(mod)
        return [] if !mod.origin.equal?(mod)
        mod.method_table.protected_names
      end

      def internal_private_instance_methods(mod)
        return [] if !mod.origin.equal?(mod)
        mod.method_table.private_names
      end

      def internal_undefined_instance_methods(mod)
        return [] if !mod.origin.equal?(mod)
        names = []
        mod.method_table.entries.each do |(name, method, visibility)|
          names << name if visibility.equal?(:undef)
        end
        names
      end

      def included_class?(object)
        object.is_a?(::Rubinius::IncludedModule)
      end

      def singleton_class?(object)
        object.is_a?(Class) && !!::Rubinius::Type.singleton_class_object(object)
      end

      def singleton_instance(singleton_class)
        singleton_class?(singleton_class) or
          raise TypeError, "expected singleton class, got #{singleton_class.class}"
        ::Rubinius::Type.singleton_class_object(singleton_class)
      end

      def module_name(mod)
        mod.is_a?(Module) or
          raise TypeError, "expected module, got #{mod.class}"

        if ::Rubinius::IncludedModule === mod
          if Class === mod.module
            "#{module_name(mod.module)} (origin)"
          else
            module_name(mod.module)
          end
        elsif ::Rubinius::Type.respond_to?(:module_name)
          ::Rubinius::Type.module_name(mod) || ''
        else
          mod.__name__
        end
      end

      def source_location(method)
        method.is_a?(UnboundMethod) or
          raise TypeError, "expected UnboundMethod, got #{method.class}"
        source_location = method.source_location and
          return source_location

        # #source_location doesn't always work. If it returns nil, try
        # a little harder.
        case (executable = method.executable)
        when ::Rubinius::BlockEnvironment::AsMethod
          method = executable.instance_variable_get(:@block_env).method
          [method.file.to_s, method.lines[1]]
        when ::Rubinius::DelegatedMethod
          executable.instance_variable_get(:@receiver).source_location
        end
      end
    end
  end
end
Something went wrong with that request. Please try again.