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.