Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • irb/extend-command.rb

IRB::MethodExtender

Public Instance Methods

def_post_proc(base_method, extend_method) click to toggle source
 
               # File irb/extend-command.rb, line 240
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 %Q[
    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) click to toggle source
 
               # File irb/extend-command.rb, line 226
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 %Q[
    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 = "__") click to toggle source

return #{prefix}#{name}#{postfix}<num>

 
               # File irb/extend-command.rb, line 255
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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.