Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8864783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:20:10+00:00 2026-06-14T16:20:10+00:00

This one’s been keeping me up at night for a while. class Foo def

  • 0

This one’s been keeping me up at night for a while.

class Foo
  def bar
    'bar'
  end

  # What the hell is going on here?!?
  alias :baz :bar
end

Foo.new.baz #=> 'bar'

Why does alias take 2 symbol as arguments, but without a comma separating them? That doesn’t seem to be any form of valid syntax in any other context. And in fact, if you do use a comma, it actually throws a syntax error.

alias :bar, :baz
# syntax error, unexpected ','

However, if I try to pass 2 symbol in the same way to my own method, it also explodes:

def somemethod(*args)
  :whatever
end
somemethod :a :b
# syntax error, unexpected ':', expecting $end
  1. So why is the alias method get to use a syntax nothing else gets to use?
  2. Is it possible to use this syntax in any other context?
  3. What is the benefit of using this odd syntax quirk, when nothing else in the language works this way? I see no discernable benefit to this language inconsistency.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:20:12+00:00Added an answer on June 14, 2026 at 4:20 pm

    The reason alias works is because it’s a Ruby keyword, similar to class, def, etc. It’s not a method.

    The alias keyword doesn’t need a comma because the Ruby designers decided it didn’t. Keywords are essentially hardcoded in the interpreter.

    There is a good reason for alias when you need to be certain the alias happens at parse time, not runtime.

    The alias keyword may be confusing or surprising. For typical development, I believe it’s better to use the Ruby method Module#alias_method, which does use a comma and works at runtime.

    Here’s a good blog post about alias and alias_method:

    This is because alias is a keyword and it is lexically scoped. It
    means it treats self as the value of self at the time the source code
    was read. In contrast alias_method treats self as the value
    determined at the run time.

    Overall my recommendation would be to use alias_method. Since
    alias_method is a method defined in class Module it can be overridden
    later and it offers more flexibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one has been stumping me for a while. But I'm no expert. This
This one has been bugging me for a while now. Is there a way
This one has been bugging me for a while now, but I never seem
This one is bit tricky , I created jsfiddle here http://jsfiddle.net/WXmcL/10/ to kinda replicate
This one has been driving me nuts. I have a div that has it's
This one is a bit tedious in as far as explaining, so here goes.
This one is tough to explain inside the title. What I have going on
This one doesn't want to compile: class MainClass { public: ... private: class NestedClass
This one fails: nice -n 10 exec $JAVA $JAVA_HEAP_MAX $NUTCH_OPTS -classpath $CLASSPATH $CLASS $@
This one is beating me, and I have not been able to figure it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.