bradgonesurfing
bradgonesurfing

Reputation: 32182

Find the source file for class / method using ri or fastri for ruby

For example I do

$fri group_by
---------------------------------------------------- Enumerable#group_by
     enum.group_by {| obj | block }  => a_hash
------------------------------------------------------------------------
     Returns a hash, which keys are evaluated result from the block, 
     and values are arrays of elements in enum corresponding to the key.

        (1..6).group_by {|i| i%3}   #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}

Except I'm pretty sure that group_by is not part of the standard ruby library. How to find out which library is monkey patching Enumerable?

Upvotes: 1

Views: 293

Answers (2)

rogerdpack
rogerdpack

Reputation: 66751

use the ri_for gem:

>> require 'ri_for'
>> Enumerable.ri_for :group_by
sig: Enumerable#group_by arity 0
appears to be a c method
Original code signature: sig: Enumerable#group_by arity 0
#parameters signature: group_by( [] )
Searching ri for
sig: Enumerable#group_by arity 0
...
Nothing known about Enumerable
(end ri)
=> "#"

(the fact that it's a c method means it's probably in core)

Upvotes: 1

mikej
mikej

Reputation: 66263

group_by is part of the ruby core since 1.8.7.

Upvotes: 2

Related Questions