New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

alias

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alias

  • 0.2.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

== Description

Creates aliases for class methods, instance methods, constants, delegated methods and more. Aliases can be easily searched or saved as YAML config files to load later. Custom alias types are easy to create with the DSL Alias provides. Although Alias was created with the irb user in mind, any Ruby console program can hook into Alias for creating configurable aliases.

== Setup

Install the gem with:

sudo gem install alias

To setup, simply drop these two lines in your .irbrc:

require 'alias' 
Alias.create

This will assume a file in config/alias.yml or ~/.alias.yml. If you want it somewhere else, pass a :file option to create():

Alias.create :file=>"/path/to/my/clandestine_aliases.yml"

If you'd like to define your aliases without a config file, pass Alias.create() an :aliases option:

Alias.create :verbose=>true, :aliases=>{
  :constant=>{'Array' = 'A'},
  :instance_method=>{'String'=>{'downcase'=>'dc' }, 'Array'=>{'select'=>'s'}}
}

== Usage

An example within Rails' script/console:

bash> script/console
>> require 'alias'
=> true

# Import alias methods
>> extend Alias::Console
=> main

# First let's see what ruby code Alias generates to create an alias.
>> create_aliases :class_method, {"ActiveRecord::Base"=>{'find'=>'[]'}}, :pretend=>true

class ::ActiveRecord::Base; class<< self; alias_method :[], :find; end; end
=> true

# Create the above class method alias
>> create_aliases :class_method, "ActiveRecord::Base"=>{'find'=>'[]'}
=> true

# Create the above constant alias
>> create_aliases :constant, "ActiveRecord::Base"=>"AB"
=> true
# Verify that it worked
>> AB
=> ActiveRecord::Base

# If we try to create the constant alias again, Alias prevents us and warns us
>> create_aliases :constant, "ActiveRecord::Base"=>"AB"
Constant 'AB' not created since it already exists
=> false
# We can force Alias to override a method, class or constant that already exists
>> create_aliases :constant, {"ActiveRecord::Base"=>"AB"}, :force=>true
=> true

# Create the above instance method alias
>> create_aliases :instance_method, "ActiveRecord::Base"=>{"update_attribute"=>'ua'}
=> true

# By default aliases are saved to config/alias.yml in rails or ~/.alias.yml if not.
>> save_aliases
Saved created aliases to config/alias.yml.
=> true

== Configuration

For an example config file see test/aliases.yml. For an explanation of the config file format see Alias.config_file.

== Creating Custom Alias Types

See Alias::Creator.

== Links

  • http://tagaholic.me/2009/07/07/alias-quickness-in-the-ruby-console.html

== Todo

  • Fix tests
  • Allow loading of select aliases in a file.
  • Provide a way to autogenerate aliases with a given proc.

FAQs

Package last updated on 24 Feb 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc