Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > how to understand Ruby code? (noting various mixins/includes) Isthere a tool to assist here?

Reply
Thread Tools

how to understand Ruby code? (noting various mixins/includes) Isthere a tool to assist here?

 
 
Greg Hauptmann
Guest
Posts: n/a
 
      12-07-2009
Hi,

I seem to spend a good deal of time trying to make sense of open
source ruby code due to the way it is very dynamic. =A0There are various
code files that are really just ready to be "mixed in" to other files
(e.g. with the class methods & instance methods ready to go). =A0Just
trying to make sense of the final object structure and where methods
resides seems to be a challenge. =A0The latest one I've been looking at
are things like AuthLogic and Paperclip which are used in the Rails
world.

QUESTION 1: =A0Is there a tool that could assist here? =A0I'm thinking of
one that could do things like walk the code base and then:

* Give a hierarchy structure where various files methods are loaded
into which objects

* Perhaps something that analyses code and then added comments to
the various files highlighting where that files methods will reside in
terms of the final object structure.

* Given sample walk throughs of methods hit in which files for a
given use case (e.g. like how the java IDEs can auto-sequence
diagrams)

QUESTION =A02: Should of nothing be available for the above, and tips/
tricks people have re understanding a new ruby codebase? (although in
particular with a rails bent)

thanks

 
Reply With Quote
 
 
 
 
Tony Arcieri
Guest
Posts: n/a
 
      12-08-2009
[Note: parts of this message were removed to make it a legal post.]

On Mon, Dec 7, 2009 at 4:47 PM, Greg Hauptmann <
http://www.velocityreviews.com/forums/(E-Mail Removed)> wrote:

> Just trying to make sense of the final object structure and where methods
> resides seems to be a challenge. The latest one I've been looking at
> are things like AuthLogic and Paperclip which are used in the Rails
> world.
>


I feel your pain, especially with AuthLogic. It's very difficult to follow
how methods are dispatched among a quagmire of mixins.

--
Tony Arcieri
Medioh/Nagravision

 
Reply With Quote
 
 
 
 
Florian Gilcher
Guest
Posts: n/a
 
      12-08-2009

On Dec 7, 2009, at 8:45 PM, Tony Arcieri wrote:

> On Mon, Dec 7, 2009 at 4:47 PM, Greg Hauptmann <
> (E-Mail Removed)> wrote:
>
>> Just trying to make sense of the final object structure and where
>> methods
>> resides seems to be a challenge. The latest one I've been looking at
>> are things like AuthLogic and Paperclip which are used in the Rails
>> world.
>>

>
> I feel your pain, especially with AuthLogic. It's very difficult to
> follow
> how methods are dispatched among a quagmire of mixins.



I found that YARD does a good job at finding static relationships
between classes
as well as informing you about them. It also provides a tool that
draws you a graph
out of them (yard-graph).

For a sample: http://yardoc.org/docs/datamapper-dm-core/DataMapper/
Model (includes
2 modules, extends another one, is defined in more then one file and
defines multiple
helper classes and modules under his namespace.

It's not 100%, but catches most reasonable cases. For more gathering,
there is still
Kernel#set_trace_fun. I experimented with a visualization for that for
university,
but it explodes horribly quick.

Regards,
Florian Gilcher

 
Reply With Quote
 
David Masover
Guest
Posts: n/a
 
      12-08-2009
On Monday 07 December 2009 05:47:11 pm Greg Hauptmann wrote:

> QUESTION 1: Is there a tool that could assist here?


Probably. I know people have written tools which generate Graphviz charts of
whole programs. I haven't used these tools, though, especially when there's
decent documentation -- so listen to the other posters on this one.

> * Given sample walk throughs of methods hit in which files for a
> given use case (e.g. like how the java IDEs can auto-sequence
> diagrams)


I don't really know what this looks like. Ruby does have a debugger, but as
you've used a Java IDE before, I assume the concept of a debugger isn't new to
you.

> QUESTION 2: Should of nothing be available for the above, and tips/
> tricks people have re understanding a new ruby codebase? (although in
> particular with a rails bent)


Well, there's always playing around in irb -- or script/console, in Rails.
There's inserting puts and p statements into the code -- with a local branch,
obviously, so you can revert those.

The best tool, though, is good documentation, and especially, read the specs,
or the tests. Rails seems to be trying to strongly encourage TDD, which means
that every intended behavior should have a descriptively-named test for it.
This will at least give you an idea of how the code is intended to be used,
and that's the very first thing you'll need before trying to understand how it
works.

 
Reply With Quote
 
Greg Hauptmann
Guest
Posts: n/a
 
      12-08-2009
thanks for the pointer to YARD - interestingly I just run across my
whole rails app (which has AuthLogic as a plugin), but it did give
some WARNINGS and finally an exception - I'll have a better look

e.g.
[warn]: in YARD::Handlers::Ruby::Legacy::ClassHandler: Undocumentable
class 'base'
[warn]: in file
'./vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_r=
ecord/schema.rb':9:

9: class << base
10: attr_accessor :defining
11: alias :defining? :defining
12:
13: alias_method_chain :define, :redhillonrails_core
14: end

/opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/templates/default/module/html/=
defines.erb:2:in
`erb': wrong argument type Symbol (expected Proc) (TypeError)
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/bin/../lib/yard/t=
emplates/template.rb:225:in
`erb'
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/templates/default=
/module/html/box_info.erb:28:in
`erb'
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/bin/../lib/yard/t=
emplates/template.rb:225:in
`erb'
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/bin/../lib/yard/t=
emplates/template.rb:306:in
`render_section'
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/bin/../lib/yard/t=
emplates/template.rb:196:in
`run'
from /opt/local/lib/ruby/1.8/erb.rb:743:in `each_with_index'
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/bin/../lib/yard/t=
emplates/template.rb:191:in
`each'
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/bin/../lib/yard/t=
emplates/template.rb:191:in
`each_with_index'
... 38 levels...
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/bin/../lib/yard/c=
li/yardoc.rb:29:in
`run'
from /opt/local/lib/ruby/gems/1.8/gems/yard-0.4.0/bin/yardoc:4
from /opt/local/bin/yardoc:19:





2009/12/8 Florian Gilcher <(E-Mail Removed)>:
>
> On Dec 7, 2009, at 8:45 PM, Tony Arcieri wrote:
>
>> On Mon, Dec 7, 2009 at 4:47 PM, Greg Hauptmann <
>> (E-Mail Removed)> wrote:
>>
>>> Just trying to make sense of the final object structure and where metho=

ds
>>> resides seems to be a challenge. =A0The latest one I've been looking at
>>> are things like AuthLogic and Paperclip which are used in the Rails
>>> world.
>>>

>>
>> I feel your pain, especially with AuthLogic. =A0It's very difficult to
>> follow
>> how methods are dispatched among a quagmire of mixins.

>
>
> I found that YARD does a good job at finding static relationships between
> classes
> as well as informing you about them. It also provides a tool that draws y=

ou
> a graph
> out of them (yard-graph).
>
> For a sample: http://yardoc.org/docs/datamapper-dm...taMapper/Model
> (includes
> 2 modules, extends another one, is defined in more then one file and defi=

nes
> multiple
> helper classes and modules under his namespace.
>
> It's not 100%, but catches most reasonable cases. For more gathering, the=

re
> is still
> Kernel#set_trace_fun. I experimented with a visualization for that for
> university,
> but it explodes horribly quick.
>
> Regards,
> Florian Gilcher
>
>




--=20
Greg
http://blog.gregnet.org/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
rails console output shows "\n" rather than putting in new line? isthere a way to change this? Greg Hauptmann Ruby 5 01-20-2009 10:47 PM
isthere any tools that could help me check include dependency between c++ files$B!)(B thinktwice C++ 10 07-01-2008 01:35 AM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM
Great tool to help understand a WebService Roger R. Smith ASP .Net Web Services 1 02-07-2004 12:06 AM



Advertisments