Class: Seasar::Util::ClassUtil
- Inherits:
-
Object
- Object
- Seasar::Util::ClassUtil
- Defined in:
- lib/seasar/util/class-util.rb
Overview
クラスに関するユーティリティクラスです。
Class Method Summary collapse
-
.get_accessor_attributes(target) ⇒ Object
-
args 1.
-
-
.get_aspectable_methods(clazz) ⇒ Object
-
args 1.
-
-
.get_instance_attributes(target) ⇒ Object
値がメソッドではない属性を返します。属性名が「_」ではじまる属性は無視されます。.
-
.module_name(clazz) ⇒ Object
return the module name.
-
.ub_name(clazz) ⇒ Object
When Class name is ‘AbcDef’, return ‘abc_def’.
Class Method Details
.get_accessor_attributes(target) ⇒ Object
-
args
-
Class target
-
-
return
-
Array
-
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/seasar/util/class-util.rb', line 49 def get_accessor_attributes(target) #method_names = (target.public_methods - Object.public_methods).map {|method_name| method_name.to_s} method_names = target.public_methods(false).map {|method_name| method_name.to_s} attributes = [] method_names.each {|name| next if name.match(/^==+$/) if name.match(/^(.+)=$/) && method_names.member?($1) attributes << "@#{$1}".to_sym end } return attributes end |
.get_aspectable_methods(clazz) ⇒ Object
-
args
-
Class clazz
-
-
return
-
Array
-
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/seasar/util/class-util.rb', line 68 def get_aspectable_methods(clazz) #methods = clazz.instance_methods - Kernel.instance_methods - Object.instance_methods methods = clazz.instance_methods - Kernel.instance_methods return methods =begin result = [] methods.each {|method_name| next if method_name[0, 1] == "_" next if method_name[-1, 1] == "_" next if method_name[-1, 1] == "?" result << method_name } return result =end end |
.get_instance_attributes(target) ⇒ Object
値がメソッドではない属性を返します。属性名が「_」ではじまる属性は無視されます。
-
args
-
Class target
-
-
return
-
Array
-
33 34 35 36 37 38 39 40 41 |
# File 'lib/seasar/util/class-util.rb', line 33 def get_instance_attributes(target) attributes = {} target.instance_variables.each {|name| next if name[1, 1] == "_" next if name[-1, 1] == "_" attributes[name.to_sym] = target.instance_variable_get(name) } return attributes end |
.module_name(clazz) ⇒ Object
return the module name. When Class name is ‘A::B::C’, return ‘A::B’ When Class name is ‘A’, return ”
-
args
-
Class clazz
-
-
return
-
String
-
108 109 110 111 |
# File 'lib/seasar/util/class-util.rb', line 108 def module_name(clazz) return '' unless clazz.name.match(/::/) return clazz.name.sub(/::\w+$/, '') end |
.ub_name(clazz) ⇒ Object
When Class name is ‘AbcDef’, return ‘abc_def’
-
args
-
Class clazz
-
-
return
-
Symbol
-
92 93 94 95 96 |
# File 'lib/seasar/util/class-util.rb', line 92 def ub_name(clazz) name = clazz.name.split(/::/).last name.gsub!(/([A-Z]+)/) { '_' + $1 } return name[1..name.length].downcase.to_sym end |