No commit activity in last 3 years
No release in over 3 years
A tool for measuring locality of Ruby source. No real features yet, wait for the non-pre version
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
 Project Readme

Cognitive Distance

Build Status

Installing

The way you install every other gem,

gem install cognitive_distance

but we're at a pre-alpha stage here, so you'd have to specify --pre, and you really shouldn't bother.

Usage

Measure the number of modules "hopped" by a method call

class Mine
  def my_method
    Yours.new.your_method
  end
end

class Yours
  def initialize
  end

  def your_method
  end
end

mine = Mine.new
CognitiveDistance.measure_module_hops { mine.my_method }
# => 2
CognitiveDistance.measure_distinct_module_hops { mine.my_method }
# => 1

The module hops are:

  1. Initializing the newly instantiated Yours object (Yours#initialize)
  2. Calling your_method on the new instance

There is only 1 distinct module hop because my_method => Yours#initialize and my_method => Yours#your_method cross the same boundary.

At this time, only Ruby code is traced, so if Yours did not define an initialize method, both hop counts would be 1.

Brief Aside: tracing c-call events changes nothing in this case, as no instance methods of the Yours instance are invoked until #your_method is called.

License

Let's go with Apache 2.0, I've been using it pretty frequently.