# Which source file?

**URL:** <https://www.ruby-forum.com/t/which-source-file/181741>\
**Category:** Ruby\
**Created:** [January 17, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/which-source-file/181741 "2010-01-17T14:46:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 17, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/which-source-file/181741/1 "2010-01-17T14:46:18Z")

</div>

Windows development environment.

After starting webrick using  
ruby script/server webrick --debugger

I started poking around and found …

* * *

(rdb:2) @devise\_mapping  
#\<Devise::Mapping:0x7182728 @for=[:authenticatable, :activatable,  
:confirmable,  
:recoverable, :rememberable, :timeoutable, :trackable, :validatable],  
@klass=“Us  
er”, @route\_options={}, @path\_names={:confirmation=\>“confirmation”,  
:password=\>"  
password", :sign\_in=\>“sign\_in”, :sign\_out=\>“sign\_out”},  
@path\_prefix="/", @name=  
:user, @as=:users\>  
(rdb:2) @devise\_mapping.class  
Devise::Mapping

* * *

Is there a convenient way to find out which source module  
defined/defines the class Devise::Mapping ?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 17, 2010, 3:28pm UTC](https://www.ruby-forum.com/t/which-source-file/181741/2 "2010-01-17T15:28:43Z")

</div>

Ralph S. wrote:

> Windows development environment.

How is that relevant?

> After starting webrick using  
> ruby script/server webrick --debugger
> 
> I started poking around and found …
> 
> * * *
> 
> (rdb:2) @devise\_mapping  
> #\<Devise::Mapping:0x7182728 @for=[:authenticatable, :activatable,  
> :confirmable,  
> :recoverable, :rememberable, :timeoutable, :trackable, :validatable],  
> @klass=“Us  
> er”, @route\_options={}, @path\_names={:confirmation=\>“confirmation”,  
> :password=\>"  
> password", :sign\_in=\>“sign\_in”, :sign\_out=\>“sign\_out”},  
> @path\_prefix=“/”, @name=  
> :user, @as=:users\>  
> (rdb:2) @devise\_mapping.class  
> Devise::Mapping
> 
> * * *
> 
> Is there a convenient way to find out which source module

What’s a source module?

> defined/defines the class Devise::Mapping ?

Yes. Use grep. Or look in the rdoc.

And remember that it might be defined in more than one place, since  
modules and classes can be reopened.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 17, 2010, 3:39pm UTC](https://www.ruby-forum.com/t/which-source-file/181741/3 "2010-01-17T15:39:03Z")

</div>

i know only Device::Mapping, maybe there is someone misspell it.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 17, 2010, 4:26pm UTC](https://www.ruby-forum.com/t/which-source-file/181741/4 "2010-01-17T16:26:41Z")

</div>

Liu Lantao wrote:

> i know only Device::Mapping, maybe there is someone misspell it.

“devise” is a gem for doing user authentication that I am beginning to  
really like.

“devise” sits on top of the Warden rack middleware to accomplish user  
authentication.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 17, 2010, 4:35pm UTC](https://www.ruby-forum.com/t/which-source-file/181741/5 "2010-01-17T16:35:25Z")

</div>

Marnen Laibow-Koser wrote:

> Ralph S. wrote:
> 
> > Windows development environment.
> 
> How is that relevant?

I don’t know! How files are handled might be different on different  
development platforms.

> > Is there a convenient way to find out which source module
> 
> What’s a source module?

A file with source code in it, Marnen.

Ask a silly question …

The word “module” … like “include” … varies in meaning depending on  
context.

> > defined/defines the class Devise::Mapping ?
> 
> Yes. Use grep. Or look in the rdoc.
> 
> And remember that it might be defined in more than one place, since  
> modules and classes can be reopened.

If, in a debugger, I enter the name of a block, the source file (er,  
module) and line number is displayed. I like that. It’s very useful.

I was hoping that there might have been a way (perhaps an array of names  
and line numbers of source files?), that Ruby/Rails would keep track of  
all the places that a class had been constructed from?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 17, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/which-source-file/181741/6 "2010-01-17T16:54:18Z")

</div>

Ralph S. wrote:

> Marnen Laibow-Koser wrote:
> 
> > Ralph S. wrote:
> > 
> > > Windows development environment.
> > 
> > How is that relevant?
> 
> I don’t know! How files are handled might be different on different  
> development platforms.

I suppose. But in this case, no. So far as I know, there’s no  
significant difference in Ruby source code handling between OSes, except  
perhaps for case-sensitivity issues. (That said, I don’t use Windows,  
so it’s conceivably that I’m not aware of something.)

> > > Is there a convenient way to find out which source module
> > 
> > What’s a source module?
> 
> A file with source code in it, Marnen.

The term “module” is never used in that sense by Ruby developers.

> Ask a silly question …
> 
> The word “module” … like “include” … varies in meaning depending on  
> context.

“Module” has exactly one meaning in a Ruby context, and that wasn’t it.  
🙂 If you mean “file”, then say it.

> > > defined/defines the class Devise::Mapping ?
> > 
> > Yes. Use grep. Or look in the rdoc.
> > 
> > And remember that it might be defined in more than one place, since  
> > modules and classes can be reopened.
> 
> If, in a debugger, I enter the name of a block, the source file (er,  
> module)

Er, file.

> and line number is displayed. I like that. It’s very useful.

Yup. The reason I didn’t originally suggest the debugger is that I was  
trying to come up with a suggestion that didn’t require knowing where to  
put a breakpoint.

> I was hoping that there might have been a way (perhaps an array of names  
> and line numbers of source files?), that Ruby/Rails would keep track of  
> all the places that a class had been constructed from?

I doubt it, but I’m not enough of a Ruby internals geek to say for sure.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 17, 2010, 5:24pm UTC](https://www.ruby-forum.com/t/which-source-file/181741/7 "2010-01-17T17:24:26Z")

</div>

Ralph S. wrote:

> > > > > Windows development environment.
> > > > 
> > > > How is that relevant?
> > > 
> > > I don’t know! How files are handled might be different on different  
> > > development platforms.
> > 
> > I suppose. But in this case, no. So far as I know, there’s no  
> > significant difference in Ruby source code handling between OSes, except  
> > perhaps for case-sensitivity issues. (That said, I don’t use Windows,  
> > so it’s conceivably that I’m not aware of something.)
> 
> Ruby (Rails?) does so much that is different depending on case.
> 
> Windows stores file names with case sensitivity but accesses the files  
> without regard to filename case.

Right. The filesystem is case-preserving but not case-sensitive.

> Thus the Filenames “SomeFile” and “Somefile” are different strings, they  
> refer to the same underlying file in Windows.
> 
> But if Rails cares about filename case sensitivity …

Rails’ autoloading routines expect snake-case filenames, so MyModel will  
be loaded from my\_model.rb.

Now, on Windows, if there’s a file My\_Model.rb, then the filesystem will  
return that when my\_model.rb is requested, whereas most \*nix filesystems  
will not.

But that’s up to the filesystem. AFAIK Ruby simply requests a particular  
file, and doesn’t know anything about how the filesystem will satisfy  
that request.

> So … does Rails care about case sensitivity in filenames?

Sort of, as outlined above.

I have found it to be best to always act as if the filesystem is  
case-sensitive, even if it isn’t.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 19, 2010, 3:58am UTC](https://www.ruby-forum.com/t/which-source-file/181741/8 "2010-01-19T03:58:31Z")

</div>

> Devise::Mapping
> 
> * * *
> 
> Is there a convenient way to find out which source module  
> defined/defines the class Devise::Mapping ?

If you’re on 1.9, you can use Method#source\_location to see where it’s  
source was defined (at least).

This tool leverages that:  
ri\_for gem

C:\> gem install ri\_for  
C:…\>script\server

# drops into a debugger

(rdb:1) require ‘ri\_for’  
(rdb:2) Devise::Mapping.ri\_for :some\_method  
(rdb:2) Devise::Mapping.desc

GL.  
-r

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 17, 2010, 5:11pm UTC](https://www.ruby-forum.com/t/which-source-file/181741/9 "2010-01-17T17:11:45Z")

</div>

> > > > Windows development environment.
> > > 
> > > How is that relevant?
> > 
> > I don’t know! How files are handled might be different on different  
> > development platforms.
> 
> I suppose. But in this case, no. So far as I know, there’s no  
> significant difference in Ruby source code handling between OSes, except  
> perhaps for case-sensitivity issues. (That said, I don’t use Windows,  
> so it’s conceivably that I’m not aware of something.)

Ruby (Rails?) does so much that is different depending on case.

Windows stores file names with case sensitivity but accesses the files  
without regard to filename case.

Thus the Filenames “SomeFile” and “Somefile” are different strings, they  
refer to the same underlying file in Windows.

But if Rails cares about filename case sensitivity …

So … does Rails care about case sensitivity in filenames?
