Skip to content

Instantly share code, notes, and snippets.

@h3h h3h/gist:1168967
Created Aug 24, 2011

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.