# Where is that method defined?

**URL:** <https://www.ruby-forum.com/t/where-is-that-method-defined/125380>\
**Category:** Ruby\
**Created:** [January 8, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/where-is-that-method-defined/125380 "2008-01-08T18:20:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [January 8, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/where-is-that-method-defined/125380/1 "2008-01-08T18:20:29Z")

</div>

I’m looking at ruby code for a class, for which I can call a method but  
which I don’t find in the class source code.

I suppose this is a feature of Ruby that I have yet to learn.  
Can anyone help me please?

Specifically, the class is Cipher in openssl module (fully qualified  
class name s OpenSSL::Cipher::Cipher) and its source code in Ruby  
library is:

```
class Cipher
  def random_key
    str = OpenSSL::Random.random_bytes(self.key_len)
    self.key = str
    return str
  end

  def random_iv
    str = OpenSSL::Random.random_bytes(self.iv_len)
    self.iv = str
    return str
  end
end

```

Where does this class defines the cipher method?

Thanks!

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [January 8, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/where-is-that-method-defined/125380/2 "2008-01-08T18:33:44Z")

</div>

it’s in C:  
\<ruby\_src\>/ext/openssl/ossl\_ssl.c line 899 (for ruby 1.8.6 source)  
rb\_define\_method(cSSLSocket, “cipher”, ossl\_ssl\_get\_cipher, 0);

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [January 8, 2008, 6:28pm UTC](https://www.ruby-forum.com/t/where-is-that-method-defined/125380/3 "2008-01-08T18:28:27Z")

</div>

Am Wed, 9 Jan 2008 02:20:26 +0900  
schrieb Alex Ma [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ```
> class Cipher
> end
> end
> 
> ```
> 
> Where does this class defines the cipher method?
> 
> Thanks!

The method may be defined in an C extension. Download ruby sources  
and lookup under ‘ext’ directory.

## – Seonic IT-Systems GbR Anton Shatalov & Markus S. Kopernikusstr.6 D-51789 Lindlar

[www.seonic.net](http://www.seonic.net)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [January 8, 2008, 8:18pm UTC](https://www.ruby-forum.com/t/where-is-that-method-defined/125380/4 "2008-01-08T20:18:02Z")

</div>

Mike McKinney wrote:

> FYI: I used the new netbeans 6 to find this quickly…
> 
> command+O: then type “Cipher”, you will see two options near the top,

Thanks!

As an aside, I’ve just installed NetBeans 6 for Ruby to give it a try.  
Probably it needs to be configured in order to behave like you’re  
mentioning. Or probably I need to be configured… 🙂  
What do you mean with command+0? I tried with ‘Navigate-\>Go to  
declaration’, but it picks the wrong one.

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [January 8, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/where-is-that-method-defined/125380/5 "2008-01-08T18:39:02Z")

</div>

FYI: I used the new netbeans 6 to find this quickly…

command+O: then type “Cipher”, you will see two options near the top,  
both  
in openssl.rb files but one is in a directory called “rubystubs” which  
tells  
me right away it’s in C and there isn’t ruby source available… the  
stub  
file doesn’t it’s best to document even those defined methods but it’s  
tough  
if there is no documentation in the C layer. then you are off to the  
source  
code for more snooping.

M

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [January 8, 2008, 8:57pm UTC](https://www.ruby-forum.com/t/where-is-that-method-defined/125380/6 "2008-01-08T20:57:06Z")

</div>

command (mac) control (win)

declaration works for classes and variables (you can control+click to  
get  
there right in your code)

but in this case, you want to choose… so you use go to type

Navigate \> goto type… enter cipher and you should have a few options  
there…

the first for me is the stubbed docs for the C impl… the second is the  
raw  
ruby for the Cipher class. (you can see the “location” at the bottom of  
the  
window which shows you where it’ll take you when you click ok or hit  
enter… rubystubs directory is where the generated ruby representing C  
impl  
is stored.)

great videos and docs here:  
[http://www.netbeans.org/features/ruby/index.html](http://www.netbeans.org/features/ruby/index.html)

NB also supports C/C++ development so you could pull the ruby source  
into  
the same IDE for viewing if you like… I’ll stop there, this is  
sounding  
too much like a commercial.

M
