Class: Module

Inherits:
Object show all
Defined in:
lib/humanized/core_ext/module.rb

Overview

This program is free software: you can redistribute it and/or modify

it under the terms of the Affero GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

(c) 2011 by Hannes Georg

Instance Method Summary collapse

Instance Method Details

#_(*args, &block) ⇒ Object



43
44
45
# File 'lib/humanized/core_ext/module.rb', line 43

def _(*args,&block)
  humanization_key._(*args,&block)
end

#humanization_keyObject

Like #humanization_key!, but cached.



39
40
41
# File 'lib/humanized/core_ext/module.rb', line 39

def humanization_key
  @humanization_key ||= humanization_key!
end

#humanization_key!Object

Generates a query for a Module or Class. This will be used by default by this Module and by all Objects of this Class.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/humanized/core_ext/module.rb', line 21

def humanization_key!
  if self.anonymous?
    return self.superclass.humanization_key
  end
  h = self.home
  if h != Object and h.respond_to?(:humanization_key) and h.method(:humanization_key).owner != Module
    result = h.humanization_key + self.basename.downcase.to_sym
  else
    result = Humanized::Query::Root.+(*self.name.split('::').map{|s| s.downcase.to_sym })
  end
  thiz = self
  if defined? thiz.superclass and self.superclass != Object
    return result | self.superclass.humanization_key
  end
  return result
end