Module: ALib::MainModule::ClassMethods
Overview
Constant Summary
Constants included
from Constants
ALib::MainModule::Constants::EXIT_FAILURE, ALib::MainModule::Constants::EXIT_SUCCESS
Constants included
from Logging
Logging::DIV0, Logging::DIV1, Logging::DIV2, Logging::DIV3, Logging::EOL, Logging::SEC0, Logging::SEC1, Logging::SEC2, Logging::SEC3
Constants included
from ALib
BSearch, Configfile, ConfigurableMain, Find, Listfile, OrderedAutoHash, SimpleMain, VERSION
Instance Method Summary
collapse
Methods included from Logging
append_features
#__logger_mutex, #__logger_sync, #btrace, #emsg, #errmsg, #log_err, #logger, #logger=
Methods included from ALib
configurable_main, export, simple_main
Instance Method Details
#class_attributes(*names) ⇒ Object
Also known as:
class_attribute, c_attrs, c_attr
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
|
# File 'lib/alib.rb', line 2128
def class_attributes(*names)
names = stringlist names
names.each do |name|
getter = "#{ name }"
setter = "#{ name }="
code = <<-code
class << self
def #{ name }(*a)
unless a.empty?
self.#{ name }= a.shift
else
@#{ name }
end
end
def #{ name }= value
@#{ name } = value
end
alias #{ name }? #{ name }
end
code
module_eval code
end
end
|
#inherited(klass) ⇒ Object
2304
2305
2306
2307
2308
2309
2310
|
# File 'lib/alib.rb', line 2304
def inherited klass
ret = super
begin; klass.class_initialize; rescue NoMethodError; end
ret
end
|
#instance_attributes(*names) ⇒ Object
Also known as:
instance_attribute, i_attrs, i_attr, attribute, attributes
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
|
# File 'lib/alib.rb', line 2099
def instance_attributes(*names)
names = stringlist names
names.each do |name|
getter = "#{ name }"
setter = "#{ name }="
code = <<-code
def #{ name }(*a)
unless a.empty?
self.#{ name }= a.shift
else
@#{ name }
end
end
def #{ name }= value
@#{ name } = value
end
alias #{ name }? #{ name }
code
module_eval code
end
end
|
#optional_arguments(*list) ⇒ Object
Also known as:
optional_argument
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
|
# File 'lib/alib.rb', line 2261
def optional_arguments(*list)
@optional_arguments ||= []
list.flatten.each do |arg|
arg, default =
case arg
when Hash
arg.to_a.first
else
[arg, nil]
end
@do_not_gc ||= []
@do_not_gc << default unless @do_not_gc.include? default
unless instance_methods.include? "#{ arg }"
module_eval <<-code
def #{ arg }(*__list)
unless @#{ arg }
@#{ arg } = ObjectSpace::_id2ref #{ default.object_id }
end
if __list.empty?
@#{ arg }
else
send('#{ arg }=', *__list)
end
end
def #{ arg }=(__arg, *__list)
if __list.empty?
@#{ arg } = __arg
else
@#{ arg } = ([__arg] + __list)
end
end
def #{ arg }?
defined? @#{ arg } and @#{ arg }
end
code
end
@optional_arguments << "#{ arg }"
end
@optional_arguments
end
|
#options(*list) ⇒ Object
Also known as:
option
2216
2217
2218
2219
2220
2221
2222
2223
|
# File 'lib/alib.rb', line 2216
def options(*list)
@optspec ||= []
return @optspec if list.empty?
list = [list] unless Array === list.first
list.each{|spec| (@optspec ||= []) << spec}
end
|
#required_arguments(*list) ⇒ Object
Also known as:
required_argument, arguments, argument
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
|
# File 'lib/alib.rb', line 2226
def required_arguments(*list)
@required_arguments ||= []
list.flatten.each do |arg|
return(optional_argument(arg)) if Hash === arg
unless instance_methods.include? "#{ arg }"
module_eval <<-code
def #{ arg }(*__list)
if __list.empty?
@#{ arg }
else
send('#{ arg }=', *__list)
end
end
def #{ arg }=(__arg, *__list)
if __list.empty?
@#{ arg } = __arg
else
@#{ arg } = ([__arg] + __list)
end
end
def #{ arg }?
defined? @#{ arg } and @#{ arg }
end
code
end
@required_arguments << "#{ arg }"
end
@required_arguments
end
|
#stringlist(*list) ⇒ Object
2093
2094
2095
2096
2097
|
# File 'lib/alib.rb', line 2093
def stringlist(*list)
list.flatten.compact.map{|item| "#{ item }".strip}
end
|
#unindent_block(buf) ⇒ Object
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
|
# File 'lib/alib.rb', line 2200
def unindent_block buf
buf = "#{ buf }"
lines = buf.to_a
indent_pat = %r/^\s*[\s|]/
indent = lines.first[ indent_pat ]
if indent
lines.map do |line|
line[ indent.size..-1 ] || "\n"
end.join
else
buf
end
end
|