Discussion on Ruby's `alias`

class Foo
def show
p "hi"
end
end

=> nil

class Foo
alias :old_show :show
def show
p "hi! I am there."
old_show
end
end

=> nil

foo = Foo.new

=> #<Foo:0x117bca0>

foo.show

"hi! I am there."
"hi"
=> "hi"

The above code is very fine. But looking for if possible to call that
`old_show` method by the object of `Foo` from `IRB main` as we called
`foo.show`? - Is this possible?

···

--
Posted via http://www.ruby-forum.com/\.

You _did_ call #old_show.

Cheers

robert

···

On Thu, Feb 28, 2013 at 1:34 PM, Tukai Patra <lists@ruby-forum.com> wrote:

class Foo
def show
p "hi"
end
end

=> nil

class Foo
alias :old_show :show
def show
p "hi! I am there."
old_show
end
end

=> nil

foo = Foo.new

=> #<Foo:0x117bca0>

foo.show

"hi! I am there."
"hi"
=> "hi"

The above code is very fine. But looking for if possible to call that
`old_show` method by the object of `Foo` from `IRB main` as we called
`foo.show`? - Is this possible?

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Uh, yes you just call it, unless I totally misunderstand your question?

class Foo
   def bar
     puts "bar"
   end
end
     ==>nil
class Foo
   alias :baz :bar
   def bar
     puts "baz"
     baz
   end
end
     ==>nil

foo = Foo.new
     ==>#<Foo:0x10bc11040>
foo.bar
baz
bar
     ==>nil
foo.baz
bar
     ==>nil

···

On 28.02.2013 12:34, Tukai Patra wrote:

class Foo
def show
p "hi"
end

=> nil

class Foo
alias :old_show :show
def show
p "hi! I am there."
old_show
end

=> nil

foo = Foo.new

=> #<Foo:0x117bca0>

foo.show

"hi! I am there."
"hi"
=> "hi"

The above code is very fine. But looking for if possible to call that
`old_show` method by the object of `Foo` from `IRB main` as we called
`foo.show`? - Is this possible?

--
Alex Gutteridge

how should ruby know that it should automatic old_show inside show?
how should it know if it should be called before or after your code or
between? what about the parameters?

that all questions ruby cant answer for you, so you need to call it
yourself when using alias

···

--
Posted via http://www.ruby-forum.com/.

class Foo
def show
p "hi"
end
end
#=> nil
class Foo
alias :old_show :show
def show
p "hi! I am there."
old_show
end
end

#=> nil
foo = Foo.new
#=> #<Foo:0x116bde8>
foo.show
"hi! I am there."
"hi"
#=> "hi"
foo.old_show
"hi"
#=> "hi"

Now say I did the below:

class Foo
def old_show
p "There is another with the same name as of mine"
end
end

foo.old_show
"There is another with the same name as of mine"
#=> "There is another with the same name as of mine"

And here `foo.old_show` is confusing.And Ruby gives the priority to the
latest `old_show` version. Now in such a
situation, - any more chance to call the aliased version of `old_show` ?

···

--
Posted via http://www.ruby-forum.com/.

How many user accounts does the same person need?

···

--
Posted via http://www.ruby-forum.com/.

Humm! That means in a large code-base, `alias` might be dangerous,where
if someone do the same what I did above.

Now my question is - is there any replacement of such `alias` which can
do the same what `alias` does above?

any replacement of the below functionality which alias does with risk
incurred with it.

class Foo
def show
p "hi"
end
end

=> nil

class Foo
alias :old_show :show
def show
p "hi! I am there."
old_show
end
end

=> nil

foo = Foo.new

=> #<Foo:0x117bca0>

foo.show

"hi! I am there."
"hi"
=> "hi"

···

--
Posted via http://www.ruby-forum.com/\.

alias is only dangerous because you do not understand it

there is no other build in way

and as i understand YOUR problem is not the alias, its the overwrite of
the aliased method above!

and its not confusing, your code is only annoying

···

--
Posted via http://www.ruby-forum.com/.

@Hans - Yes I do understand how `alias` works. Might be you didn't catch
my aim. I have a hope anyone out there might understood my intention.
Let's wait you can see how the same could be done with other way's,if
someone answered it. Meanwhile If I get any solution,I will present here
with explanation.

Don't worry. :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.

as i said above,
* you cant made that the orginal method is automatic called (your first
question)
* you cant prevent that the alias method will be overwritten (your
second question)

that is not how ruby/alias works ... live with that!

and ignoring other users that wants to help you is not a nice way in
this forum

···

--
Posted via http://www.ruby-forum.com/.

How many user accounts does the same person need?

Yes, this guy here sounds like ILoveRuby ... :\

That means in a large code-base, `alias` might be dangerous
where if someone do the same what I did above.

I use alias all the time.

Ruby-gnome uses aliases all over the place.

Can you believe this?

It does not seem dangerous at all, it simply works.

Now my question is - is there any replacement of
such `alias` which can do the same what `alias`
does above?

Do you speak the english language?

You basically asked:

"is there a replacement for alias that can do
what alias can do"

Yes. The name is:

  alias

There is also alias_method but since you ask fake
questions anyway, I am sure you'll ignore that.

any replacement of the below functionality
which alias does with risk incurred with it.

There is no risk.

I think you need to use PHP, please improve PHP
and not try to "improve" ruby.

And, by the way, if you were serious, you would
go over to bugs ruby-lang and file feature
requests.

···

--
Posted via http://www.ruby-forum.com/\.

See the below link:

And people who cursed me and tried repeatedly to be off-topic by
pointing me to the other users, to whom I am not familiarized with
anyway instead.

people here have very bad conception,they did have time to get busy with
bad discussions.

Still apologies if I disrespect one. But you did that with me.

anyway Thanks.

···

--
Posted via http://www.ruby-forum.com/.

You obviously didn't even try to just call the #old_show method.

Arup Rakshit, Love U Ruby, Xavier R., Tukai Patra:

When you think we are so stupid that we do not recognize you in spite
of your new user names then you shouldn't ask us for help.

···

Am 28.02.2013 13:34, schrieb Tukai Patra:

class Foo
def show
p "hi"
end

=> nil

class Foo
alias :old_show :show
def show
p "hi! I am there."
old_show
end

=> nil

foo = Foo.new

=> #<Foo:0x117bca0>

foo.show

"hi! I am there."
"hi"
=> "hi"

The above code is very fine. But looking for if possible to call that
`old_show` method by the object of `Foo` from `IRB main` as we called
`foo.show`? - Is this possible?

--
<https://github.com/stomar/&gt;

Robert Klemme wrote in post #1099527:

···

On Thu, Feb 28, 2013 at 1:34 PM, Tukai Patra <lists@ruby-forum.com> > wrote:

old_show

The above code is very fine. But looking for if possible to call that
`old_show` method by the object of `Foo` from `IRB main` as we called
`foo.show`? - Is this possible?

You _did_ call #old_show.

Cheers

robert

Yes, but that I did inside from the `show`. I am telling if possible to
call the same `old_show` without the help of `show`?

--
Posted via http://www.ruby-forum.com/\.

Alex Gutteridge wrote in post #1099529:

···

On 28.02.2013 12:34, Tukai Patra wrote:

old_show

Uh, yes you just call it, unless I totally misunderstand your question?

class Foo
   def bar
     puts "bar"
   end
end
     ==>nil
class Foo
   alias :baz :bar
   def bar
     puts "baz"
     baz
   end
end

in the above you put `baz` inside `bar`, thus you were able. I am
telling without putting it into any instance method, can we call it,from
the outside of the class?

Hope myself cleard now my intention.

--
Posted via http://www.ruby-forum.com/\.

Alex Gutteridge wrote in post #1099529:

old_show

class Foo
   def bar
     puts "bar"
   end
end
     ==>nil
class Foo
   alias :baz :bar
   def bar
     puts "baz"
     baz
   end
end
     ==>nil

foo = Foo.new
     ==>#<Foo:0x10bc11040>

Yes the below one I was looking for if possible or not. Can you explain
how does it possible? what internal task ruby did for that call?

foo.baz
bar
     ==>nil

Sorry I overlooked it :slight_smile:

···

On 28.02.2013 12:34, Tukai Patra wrote:

--
Posted via http://www.ruby-forum.com/\.

Tukai Patra wrote in post #1099551:

And here `foo.old_show` is confusing.And Ruby gives the priority to the
latest `old_show` version. Now in such a
situation, - any more chance to call the aliased version of `old_show` ?

you itself does "overwrite" the method, you dont get it back, the old
version is GONE

and its not confusing it is clear if you try to think

···

--
Posted via http://www.ruby-forum.com/\.

Tukai/Xavier/Love U Ruby/Arup,

Go away and don't come back until you have spent some time actually
learning the basics of Ruby. Also, don't come back until you learn to be
respectful to people helping you. The fact that you keep making new
usernames is not only annoying but it's just pointing out that even
*you* know you are annoying the piss out of others on this mailing list.

-Ryan

···

On 2/28/13 9:54 AM, Hans Mackowiak wrote:

as i said above,
* you cant made that the orginal method is automatic called (your first
question)
* you cant prevent that the alias method will be overwritten (your
second question)

that is not how ruby/alias works ... live with that!

and ignoring other users that wants to help you is not a nice way in
this forum

@Hans - Yes I do understand how `alias` works. Might be you didn't catch
my aim. I have a hope anyone out there might understood my intention.

I hope *you* do.

Let's wait you can see how the same could be done with other way's,if
someone answered it. Meanwhile If I get any solution,I will present here
with explanation.

Facts:

1. With alias you copy a method.
2. You can achieve the same with alias_method.
3. You can achieve something similar by doing def new_meth(*a,&b)
old_meth(*a,&b) end.
4. When defining a method all previous definitions under that name are gone.
5. Option 2 and 1 actually differ from 3 if you redefine old_meth
(exercise for the user).
6. What constitutes dangerous depends on the expectations and the
desired behavior.
7. Invoking a method from inside or outside an object (meaning self
pointing to the instance to invoke the method on or not) only matters
for private methods.

irb(main):001:0> class Foo
irb(main):002:1> def x; 1; end
irb(main):003:1> alias_method :y, :x
irb(main):004:1> end
=> Foo
irb(main):005:0> Foo.new.y
=> 1
irb(main):006:0> class Foo
irb(main):007:1> def x; 2; end
irb(main):008:1> end
=> nil
irb(main):009:0> Foo.new.y
=> 1
irb(main):010:0> Foo.new.x
=> 2

Cheers

robert

···

On Thu, Feb 28, 2013 at 4:50 PM, Tukai Patra <lists@ruby-forum.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

You obviously didn't even try to just call the #old_show method.

Arup Rakshit, Love U Ruby, Xavier R., Tukai Patra:

When you think we are so stupid that we do not recognize you in spite
of your new user names then you shouldn't ask us for help.

···

---------------------------------------------------------------------------------------------
From Trolls with multiple handles:

I am now convinced (as many of you are aware) there are various trolls with multiple handles whose sole purpose is to infiltrate well meaning threads with obfuscation and red herrings and with the intent to dummy down and discredit whatever topic is being discussed.

Now, these are not your typical die-hard skeptics or die-hard believers. These are people who intentionally try to railroad threads with nonsensical arguments or off-topic rants.

You can usually spot them due to their activity level, stars, flag counts, etc.
----------------------------------------------------------------------------------------------
Far too many of the questions posed are easily found . "Google is your friend". And too many meaningful answers are ignored. Even our maxim MINSWAN can be pushed to it's limits.

Lets go with 'YAATSGFY' and use this as the sole content of all replies to questions and comments posed by this troll.

Maybe he (or she) will start to get the message...