Ruby creates a method alias with the same name as "keyword" _ruby topic

Source: Internet
Author: User
Tags instance method

Begin and end are keywords for Ruby, but there is also an instance method with the name begin and end in range. Now the question is: How do you create their alias method?

If it doesn't work with class Range;alias begin_x begin end, Ruby thinks the next begin is the beginning of a grammar block:

Copy Code code as follows:

2.1.2:089 > class Range;alias begin0 begin End
2.1.2:090?>

With class Range;alias begin_x "Begin" End also not, with the alias Begin_x:begin or not!

Copy Code code as follows:

2.1.2:083 > class Range
2.1.2:084?> alias Begin0:begin
2.1.2:085 > End
2.1.2:086?> End
SyntaxError: (IRB): 86:syntax error, unexpected keyword_end, expecting End-of-input
From/users/apple/.rvm/rubies/ruby-2.1.2/bin/irb:11:in ' <main> '
2.1.2:087 > class Range;alias begin0 "Begin" End
SyntaxError: (IRB): 87:syntax error, unexpected Tstring_beg
Class Range;alias Begin0 "Begin" End
^
From/users/apple/.rvm/rubies/ruby-2.1.2/bin/irb:11:in ' <main> '

Is there any more? I suddenly thought of this grammar: alias begin_x: "Begin", this time oh bird! The same end method is similar.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.