Skip to content

Instantly share code, notes, and snippets.

@h3h
Created August 24, 2011 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3h/1168967 to your computer and use it in GitHub Desktop.
Save h3h/1168967 to your computer and use it in GitHub Desktop.
Ruby's `alias_method` Behavior
>> class Foo
> def bar; 1 end
> alias_method :baz, :bar
> end
=> Foo
>> class FooTwo < Foo
> def bar; 2 end
> end
=> nil
>> FooTwo.new.bar
=> 2
>> FooTwo.new.baz
=> 1
@jneen
Copy link

jneen commented Aug 25, 2011

I've used this before, and found it very convenient - it does exactly what you'd expect:

class Module
  def soft_alias(from, to)
    define_method(from) do |*args, &blk|
      send(to, *args, &blk)
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment