views:

53

answers:

2
  def self.source_root
    File.join(File.dirname(__FILE__), 'templates')
  end
+3  A: 

This means that you can call Class.source_root on a class and it will return it's path name with 'templates' appended on the end. So say you had

Class User
  def self.source_root
    File.join(File.dirname(__FILE__), 'templates')
  end
end

In the directory application/model/

If you call

User.source_root

It returns

"application/model/templates"
AndrewKS
Very cool. Thanks!
AnApprentice
A: 

Use irb to see what it does. You can debug variables and test what they do.

It's a class method so you can create a class in irb and test what it does.

Run irb like so :-

irb(main):001:0> def self.source_root

irb(main):002:1> File.join(File.dirname(FILE), 'templates')

irb(main):003:1> end => nil

irb(main):004:0> class Foo

irb(main):005:1> def self.source_root

irb(main):006:2> File.join(File.dirname(FILE), 'templates')

irb(main):007:2> end

irb(main):008:1> end

=> nil

irb(main):009:0> Foo.source_root

=> "./templates"

irb(main):010:0>

irb(main):010:0> FILE

=> "(irb)"

irb(main):011:0> File.dirname(FILE)

=> "."

abdollar