Aliasing operators possible?

G

GGarramuno

I'd like to alias the =~ operator, is this possible?

This is what I'm doing and what I get:

Normal aliasing of a method (all fine):

irb(main):015:0> class String
irb(main):016:1> alias :eek:ldsub :sub
irb(main):017:1> def sub(a,b)
irb(main):018:2> p "sub"
irb(main):019:2> oldsub(a,b)
irb(main):020:2> end
irb(main):021:1> end

irb(main):027:0>"abc".sub(/a/,"")
"sub"
=> "bc"

------------------------------------------

Aliasing of =~ (not fine)

irb(main):001:0> class String
irb(main):002:1> alias :eek:ld=~ :=~
irb(main):003:1> def =~(pat)
irb(main):004:2> p "new"
irb(main):005:2> old=~(pat)
irb(main):006:2> end
irb(main):007:1> end

SyntaxError: compile error
(irb):2: syntax error
alias :eek:ld=~ :=~
^
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top