Module: IRB::MethodExtender
- Defined in:
- lib/irb/extend-command.rb
Instance Method Summary collapse
- #def_post_proc(base_method, extend_method) ⇒ Object
- #def_pre_proc(base_method, extend_method) ⇒ Object
-
#new_alias_name(name, prefix = "__alias_of__", postfix = "__") ⇒ Object
return #prefix#name#postfix<num>.
Instance Method Details
#def_post_proc(base_method, extend_method) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/irb/extend-command.rb', line 242 def def_post_proc(base_method, extend_method) base_method = base_method.to_s extend_method = extend_method.to_s alias_name = new_alias_name(base_method) module_eval %[ alias_method alias_name, base_method def #{base_method}(*opts) send :#{alias_name}, *opts send :#{extend_method}, *opts end ] end |
#def_pre_proc(base_method, extend_method) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/irb/extend-command.rb', line 228 def def_pre_proc(base_method, extend_method) base_method = base_method.to_s extend_method = extend_method.to_s alias_name = new_alias_name(base_method) module_eval %[ alias_method alias_name, base_method def #{base_method}(*opts) send :#{extend_method}, *opts send :#{alias_name}, *opts end ] end |
#new_alias_name(name, prefix = "__alias_of__", postfix = "__") ⇒ Object
return #prefix#name#postfix<num>
257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/irb/extend-command.rb', line 257 def new_alias_name(name, prefix = "__alias_of__", postfix = "__") base_name = "#{prefix}#{name}#{postfix}" all_methods = instance_methods(true) + private_instance_methods(true) same_methods = all_methods.grep(/^#{Regexp.quote(base_name)}[0-9]*$/) return base_name if same_methods.empty? no = same_methods.size while !same_methods.include?(alias_name = base_name + no) no += 1 end alias_name end |