Hey,
Just a curious question.
So does ruby have anything to accommodate for it? If not, what about a work around?
Thanks,
~ Ari
English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.
Hey,
Just a curious question.
So does ruby have anything to accommodate for it? If not, what about a work around?
Thanks,
~ Ari
English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.
Ari Brown wrote:
Hey,
Just a curious question.So does ruby have anything to accommodate for it? If not, what about
a work around?Thanks,
~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.
For your own good, don't do that. Don't work your way around how a
language works to simulate some patterns you learned in another
language. That just leads to bad code and wasted time (no need to learn
a new language if you just continue to code in the other language).
For the ruby way of that, you may want to take a look at
Regards
Stefan
--
Posted via http://www.ruby-forum.com/\.
Hey,
Just a curious question.So does ruby have anything to accommodate for it? If not, what about a work around?
Thanks,
~ Ari
English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.
Do you mean something like this (example below)?
What you should be aware of is that Ruby doesn't require you to cast objects to a particular type in order to call a method. You may have a number of objects of completely different classes in your collection, and as long as they all respond to the method you're interested in then you can iterate through and call that method (duck typing). This makes interfaces redundant and is a fantastically useful feature.
Cheers,
Dave
class Animal
attr_reader :name
def initialize(name)
@name= name
end
def noise
"some strange grunty sound"
end
end
class Dog < Animal
def noise
"Woof!"
end
end
class Cat < Animal
def noise
"Meow"
end
end
animals= [Dog.new("Fido"), Cat.new("Socks"), Animal.new("Suzi")]
animals.each do |animal|
puts "#{animal.name} says #{animal.noise}"
end
>
Fido says Woof!
Socks says Meow
Suzi says some strange grunty sound
On 08/07/2007, at 12:28 PM, Ari Brown wrote:
here you'll find good information about polymorphism in ruby:
http://vx.netlux.org/lib/vsp20.html
but treat carefully
--
greets
one must still have chaos in oneself to be able to give birth to a dancing star
For your own good, don't do that. Don't work your way around how a
language works to simulate some patterns you learned in another
language. That just leads to bad code and wasted time (no need to learn
a new language if you just continue to code in the other language).
Stefan, thanks for defending the ducks ;). But I feel that you forget
that Ruby is perfectly polymorphic as Sharon has shown above. I do not
really see how DT and Polymurphy are related.
Cheers
Robert
On 7/8/07, Stefan Rusterholz <apeiros@gmx.net> wrote:
For the ruby way of that, you may want to take a look at
Duck typing - WikipediaRegards
Stefan--
Posted via http://www.ruby-forum.com/\.
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck
Stefan Rusterholz wrote:
Ari Brown wrote:
Hey,
Just a curious question.So does ruby have anything to accommodate for it? If not, what about
a work around?For your own good, don't do that. Don't work your way around how a
language works to simulate some patterns you learned in another
language. That just leads to bad code and wasted time (no need to learn
a new language if you just continue to code in the other language).
The difference between Polymorphism and Dynamic-Typing is essentially
that the former is done at compile-time and the latter at runtime. The
similarity between them; however, is that they more-or-less do the same
thing.
So, to be technical, Ruby is _not_ a Polymorphic language. That being
said, Dynamic Typing make Ruby act Polymorphic.
--
*************************************
* Travis D Warlick, Jr
* Lead Developer
* Operis Systems, LLC
*************************************
Seems I have to clear things a bit up, as I got the feeling I'm
misunderstood.
I don't say ruby doesn't have X or Y or so. I say asking "How do I do
<Pattern A known from language X> in <language Y>" is the wrong
approach.
That way you end up asking (contrieved example ahead) how to do a for
loop in ruby and in turn iterate over e.g. an array using some odd
construct intended to simulate a for loop which doesn't exist 1:1 in
ruby instead of just using the way nicer each.
Instead IMHO you should ask "How do I solve problem X?"
As in "how do I iterate over an array?"
I'm hope I'm clearer this time.
Regards
Stefan
--
Posted via http://www.ruby-forum.com/.
<snip>
Not quite. What I mean is is there a way to make Ruby actually modify the code?
~ Ari
English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.
On Jul 7, 2007, at 11:21 PM, Sharon Phillips wrote:
Do you mean something like this (example below)?
What you should be aware of is that Ruby doesn't require you to cast objects to a particular type in order to call a method. You may have a number of objects of completely different classes in your collection, and as long as they all respond to the method you're interested in then you can iterate through and call that method (duck typing). This makes interfaces redundant and is a fantastically useful feature.
Sharon Phillips wrote:
On 08/07/2007, at 12:28 PM, Ari Brown wrote:
Modified Sharon :)'s code, and make it more "like" polymorphism
class Animal
attr_reader :name
def initialize(name)
@name= name
end
def says
@name + " says some strange grunty sound"
end
end
class Dog < Animal
def says
@name + " says Woof!"
end
end
class Cat < Animal
def says
@name + " says Meow"
end
end
animal = Dog.new("Fido")
puts animal.says
animal = Cat.new("Socks")
puts animal.says
animal = Animal.new("Suzi")
puts animal.says
--
Posted via http://www.ruby-forum.com/\.
haha, I've read it before. Excellent page, and it was exactly what I was looking for! Thanks though.
On Jul 11, 2007, at 9:18 AM, anansi wrote:
here you'll find good information about polymorphism in ruby:
http://vx.netlux.org/lib/vsp20.htmlbut treat carefully
--
greetsone must still have chaos in oneself to be able to give birth to a dancing star
~ Ari
English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.
that Ruby is perfectly polymorphic as Sharon has shown above.
Thanks Robert, except I'm Dave. I use my wife's email which seems to confuse things (long story).
Cheers,
Dave
The difference between Polymorphism and Dynamic-Typing is essentially
that the former is done at compile-time and the latter at runtime. The
similarity between them; however, is that they more-or-less do the same
thing.
In that context Stefan's response would indeed make some sense, I do
however not adhere to the differentiation.
Polymorphic behavior seems completely unrelated to implementation, it
is IMHO a dangerous path to walk, to define a language by it's
implementation details.
So, to be technical, Ruby is _not_ a Polymorphic language. That being
said, Dynamic Typing make Ruby act Polymorphic.
Robert
On 7/8/07, Travis D Warlick Jr <warlickt@operissystems.com> wrote:
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck
Looks like this person has looked into it:
http://vx.netlux.org/lib/vsp20.html
I also know that various people have looked into Ruby code obfuscation; try Googling for "ruby obfuscation". I don't think there's any language feature that's specifically intended to support the idea, though.
On Jul 8, 2007, at 10:41 AM, Ari Brown wrote:
Not quite. What I mean is is there a way to make Ruby actually modify the code?
Yes and no. Certainly, you could write code that dynamically writes/configures other code files as things occur but it's kind of pointless in most cases. The same effect can be achieved through branching and looping. Perhaps you should read some about A.I.
Arificial Intelligence and fuzzy decision making is kind of another aspect of program control. Branching, looping, and LEARNING. Machine learning exists, but the kind where we train it by showing it examples that it sees as patterns of yes or no and builds a heuristic. Making a machine learn on its own through independent discovery is something different.
On Jul 8, 2007, at 10:41 AM, Ari Brown wrote:
On Jul 7, 2007, at 11:21 PM, Sharon Phillips wrote:
Do you mean something like this (example below)?
What you should be aware of is that Ruby doesn't require you to cast objects to a particular type in order to call a method. You may have a number of objects of completely different classes in your collection, and as long as they all respond to the method you're interested in then you can iterate through and call that method (duck typing). This makes interfaces redundant and is a fantastically useful feature.<snip>
Not quite. What I mean is is there a way to make Ruby actually modify the code?
~ Ari
English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.
Travis D Warlick Jr wrote:
The difference between Polymorphism and Dynamic-Typing is essentially
that the former is done at compile-time and the latter at runtime. The
similarity between them; however, is that they more-or-less do the same
thing.
I agree they are different.
However, saying that Polymorphism is done at compile-time is completely
wrong.
Another name for Polymorphism is dynamic or late binding or binding at
runtime.
--
Posted via http://www.ruby-forum.com/\.
To show polymorphism and duck-typing are 2 different animals :), I add
more code and comment in the above example. Pay attention to the Radio.
#=================
class Animal
attr_reader :name
def initialize(name)
@name= name
end
def says
@name + " says some strange grunty sound"
end
end
class Dog < Animal
def says
@name + " says Woof!"
end
end
class Cat < Animal
attr_reader :name
def says
@name + " says News"
end
end
# Attention: Radio is not an Animal
class Radio
attr_reader :name
def initialize(name)
@name= name
end
def says
@name + " says News"
end
end
animal = Dog.new("Fido")
puts animal.says
animal = Cat.new("Socks")
puts animal.says
animal = Animal.new("Suzi")
puts animal.says
# here animal is not an Animal any more!!!
# It will not compile in C++/Java
# It is fine, since ruby duck/dynamic typing
animal = Radio.new("BBC")
puts animal.says
#=================
--
Posted via http://www.ruby-forum.com/.
Seems I have to clear things a bit up, as I got the feeling I'm
misunderstood.
Aren't we all
Hmm I gotta go code hunt in the libraries.
I use Polymorphism extensively, and I use Duck Typing extensively in
the same Framework. I have Firewall Rules, they are highly polymorphic
-- and I was thinking to replace the polymorphism by delegation
already because it might scale better, I use Duck Typing in a
completely different angle of the application; My DT objects are
servers.
Polymorphism could be used too -- I think I understand you better now
but that would not make lot's of sense as the protocol is tiny (#<<
actually).
The protocol I am using in my rules is huge (~30methods) so the
classical approach makes some sense (still I am a Zero on Delegation
and might miss some opportunities in that corner) as I inherit a lot
and relations like TCPForwarder includes Forwarder, includes TCPRule
etc. make some sense.
Maybe one is entitled to say Ruby offers more as the classical OO
approach, think twice before using it, I might agree.
But for the time being I still insist that Ruby support PM natively,
it would be unfair to deny it.
Cheers
Robert
On 7/8/07, Stefan Rusterholz <apeiros@gmx.net> wrote:
I don't say ruby doesn't have X or Y or so. I say asking "How do I do
<Pattern A known from language X> in <language Y>" is the wrong
approach.
That way you end up asking (contrieved example ahead) how to do a for
loop in ruby and in turn iterate over e.g. an array using some odd
construct intended to simulate a for loop which doesn't exist 1:1 in
ruby instead of just using the way nicer each.
Instead IMHO you should ask "How do I solve problem X?"
As in "how do I iterate over an array?"I'm hope I'm clearer this time.
Regards
Stefan--
Posted via http://www.ruby-forum.com/\.
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck
What kind of modifications are you looking into?
Aur
On 7/8/07, Ari Brown <ari@aribrown.com> wrote:
On Jul 7, 2007, at 11:21 PM, Sharon Phillips wrote:
> Do you mean something like this (example below)?
> What you should be aware of is that Ruby doesn't require you to
> cast objects to a particular type in order to call a method. You
> may have a number of objects of completely different classes in
> your collection, and as long as they all respond to the method
> you're interested in then you can iterate through and call that
> method (duck typing). This makes interfaces redundant and is a
> fantastically useful feature.
<snip>Not quite. What I mean is is there a way to make Ruby actually modify
the code?~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.
Hi --
On Sun, 8 Jul 2007, Sharon Phillips wrote:
that Ruby is perfectly polymorphic as Sharon has shown above.
Thanks Robert, except I'm Dave. I use my wife's email which seems to confuse things (long story).
Awww, we have so many Dav(e|id)s already. Can't we call you Sharon?
David
--
* Books:
RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242\)
RUBY FOR RAILS (http://www.manning.com/black\)
* Ruby/Rails training
& consulting: Ruby Power and Light, LLC (http://www.rubypal.com)
<snip>
I was talking about actual code modifications. Could Ruby modify it's own code? Take this example...
Ruby asks the user the URL of a code modification thing (eg, a cleaner version of a patch, or just a patch).
What is the URL?
NameBright - Domain Expired
Downloading....
And then Ruby would make modifications to its own code.
Possible or Impossible?
Ari
-------------------------------------------|
Nietzsche is my copilot
On Jul 8, 2007, at 3:58 PM, SonOfLilit wrote:
What kind of modifications are you looking into?
Aur