Roseanne Zhang wrote:
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.
Thanks for the correction. I had to go back to my Programming Languages
book to check myself, and you are quite correct. Not sure what I was
thinking...
···
--
Travis
You mean like a Software Update system? yes.
Lots of software does it.
The only thing is that some parts of the program can't be safely modified at runtime.
that's why some system or application software updates/patches require you to restart your computer.
The risky part is overstepping bounds. If one application or the system is using something, and you alter it, it is often possible to have the original process believing some_thing is at memory_address_X, when it is now at memory_address_y.
Stuff like that. Can be messy business.
On the other hand, it depends what you want to update or modify. Clearly a lot is possible.
Think of what irb can do.
Luckily ruby will generally just complain about a nil object that wasn't expected. so it increases the need for error handling.
···
On Jul 8, 2007, at 3:31 PM, Ari Brown wrote:
On Jul 8, 2007, at 3:58 PM, SonOfLilit wrote:
What kind of modifications are you looking into?
Aur
<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
I'm not sure Ruby, the interpreter, can, but a Ruby /script/ can.
Since you can reopen classes, it's possible to load arbitrary source
code, evaluate it (or just use 'load'), and then have the changes
reflected.
For example, if your main file was something like this (untested!):
require 'open-uri'
class X; def foo; "bar"; end; end
puts X.new.foo # => "bar"
puts "What is the URL?"
eval open(gets).read
puts X.new.foo # => "no bar for you"
And some remote Ruby file called "something.rb" was like this:
class X; def foo; "no bar for you"; end; end
And you ran the first file and specified
http://domain.com/something.rb .. then, in theory, (and this is all
untested), the functionality of the initial program is changed. You
could then, in theory, save the "patch" to a local file and add it to
a list of "patches" to apply on future executions. Rails' use of
plugins treads into some of these areas.
This all gets dangerous very quickly though, but I just wanted to
answer the question you asked as I hadn't seen any answers so far (you
mean polymorphic, as in polymorphic viruses, rather than polymorphism,
it seems).
Cheers,
Peter Cooper
···
On 7/8/07, Ari Brown <ari@aribrown.com> wrote:
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.
Definitely doable. Just use load to load the changes. You would also have to look at the current object space and make you adjustments. I believe that changes to a class don't modify its already existing instances. But you can always add and remove behavior of an object.
Diego Scataglini
···
On Jul 8, 2007, at 4:31 PM, Ari Brown <ari@aribrown.com> wrote:
On Jul 8, 2007, at 3:58 PM, SonOfLilit wrote:
What kind of modifications are you looking into?
Aur
<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
Ok, so since you've just been back to the book, please explain what
the term means in non-geek language!
···
On Tue, 10 Jul 2007 00:00:21 +0900, Travis D Warlick Jr wrote:
Roseanne Zhang wrote:
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.
Thanks for the correction. I had to go back to my Programming
Languages book to check myself, and you are quite correct. Not
sure what I was thinking...
--
Chris Game
"If everything seems under control, you're
just not going fast enough." -- Mario Andretti
+1 for Ruby gender bending method
···
On Jul 8, 2007, at 7:33 AM, Wayne E. Seguin wrote:
On Jul 08, 2007, at 07:37 , dblack@wobblini.net wrote:
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?

+1 for Sharon 
--
Wayne E. Seguin
Sr. Systems Architect & Systems Admin
wayneseguin@gmail.com
<snip>
You mean like a Software Update system? yes.
Lots of software does it.
The only thing is that some parts of the program can't be safely modified at runtime.
that's why some system or application software updates/patches require you to restart your computer.
The risky part is overstepping bounds. If one application or the system is using something, and you alter it, it is often possible to have the original process believing some_thing is at memory_address_X, when it is now at memory_address_y.
Stuff like that. Can be messy business.
On the other hand, it depends what you want to update or modify. Clearly a lot is possible.
Think of what irb can do.
Luckily ruby will generally just complain about a nil object that wasn't expected. so it increases the need for error handling.
Nice!
Is there a suggested library or method to use for that? Or is it just something I could hack together?
--------------------------------------------|
If you're not living on the edge,
then you're just wasting space.
···
On Jul 8, 2007, at 4:56 PM, John Joyce wrote:
But, I take it, I can't modify this single script, right?
Start:
file.rb
so that after I download a new patch, all that's left is:
file.rb
···
On Jul 8, 2007, at 5:31 PM, diego scataglini wrote:
Definitely doable. Just use load to load the changes. You would also have to look at the current object space and make you adjustments. I believe that changes to a class don't modify its already existing instances. But you can always add and remove behavior of an object.
Diego Scataglini
~ Ari
English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.
C:\>irb
irb(main):001:0> class Foo; def sq(x) x*x end; end
irb(main):002:0> f = Foo.new
irb(main):003:0> f.sq( 12 )
=> 144
irb(main):004:0> class Foo; def double(x) x+x end; end
irb(main):005:0> f.double( 21 )
=> 42
irb(main):006:0> class Foo; def sq(x) x*x*x end; end
irb(main):007:0> f.sq( 12 )
=> 1728
···
On Jul 8, 3:31 pm, diego scataglini <dwebsub...@gmail.com> wrote:
I believe that changes to a class don't modify its already existing
instances. But you can always add and remove behavior of an object.
Yes, you can do that.
Also, like Diego mentioned about changing behavior of an object when
loading code ... say I have a file test.rb that looks like this:
class C
def f(x)
puts x
end
end
and I go into irb ...
irb(main):001:0> load 'test.rb'
=> true
irb(main):002:0> c = C.new
=> #<C:0x2df909c>
irb(main):003:0> c.f 1
1
=> nil
irb(main):004:0> c.g 1
NoMethodError: undefined method 'g' for #<C:0x2df909c>
from (irb):4
leaving irb sitting there just the way it is, I modify test.rb by
adding this method to class C:
def g x
puts x + 1
end
back to irb...
irb(main):005:0> c.g 1
NoMethodError: undefined method 'g' for #<c:0x2df909c>
from (irb):1
irb(main):006:0> load 'test.rb' #reloading the file, but _not_ creating a new c
=> true
irb(main):007:0> c.g 1
2
=> nil
Todd
···
On 7/9/07, Ari Brown <ari@aribrown.com> wrote:
But, I take it, I can't modify this single script, right?
Start:
file.rb
so that after I download a new patch, all that's left is:
file.rb
Thank you for the correction =)
Diego Scataglini
···
On Jul 11, 2007, at 9:19 AM, Phrogz <phrogz@mac.com> wrote:
On Jul 8, 3:31 pm, diego scataglini <dwebsub...@gmail.com> wrote:
I believe that changes to a class don't modify its already existing
instances. But you can always add and remove behavior of an object.
C:\>irb
irb(main):001:0> class Foo; def sq(x) x*x end; end
irb(main):002:0> f = Foo.new
irb(main):003:0> f.sq( 12 )
=> 144
irb(main):004:0> class Foo; def double(x) x+x end; end
irb(main):005:0> f.double( 21 )
=> 42
irb(main):006:0> class Foo; def sq(x) x*x*x end; end
irb(main):007:0> f.sq( 12 )
=> 1728
You can totally do it. It's pretty common. You might want to make a temp file while updating, so you can check to make sure the whole thing is complete before committing to the new file.
The caveat is just data corruption when objects are in use and if they're suddenly gone when you try to access them.
If you think this might happen, it is best to have a script download the new file, along with a configuration script that starts when the program is restarted. Essentially, you want a hook in your original program to check for any updates to run at program start. It's a very low cost. Just a quick if statement looking into a data file (or looking for one) that says there is or is not an update to apply. Multiple 'load's of the same file in irb usually work fine (as an example) but occasionally will blow up and make you need to force-quit irb.
Example, your code enters a looping mechanism, something is loaded that removes or prevents the looping exit condition, voila... infinite loop. So, you just need to be careful how you implement the update mechanism. Transparent to the user (as much as possible) is nice, but no crash/hang/runaway process is better for the user (even if they don't know it).
John Joyce
···
On Jul 9, 2007, at 5:55 PM, Todd Benson wrote:
On 7/9/07, Ari Brown <ari@aribrown.com> wrote:
But, I take it, I can't modify this single script, right?
Start:
file.rb
so that after I download a new patch, all that's left is:
file.rb
Yes, you can do that.
Also, like Diego mentioned about changing behavior of an object when
loading code ... say I have a file test.rb that looks like this:
class C
def f(x)
puts x
end
end
and I go into irb ...
irb(main):001:0> load 'test.rb'
=> true
irb(main):002:0> c = C.new
=> #<C:0x2df909c>
irb(main):003:0> c.f 1
1
=> nil
irb(main):004:0> c.g 1
NoMethodError: undefined method 'g' for #<C:0x2df909c>
from (irb):4
leaving irb sitting there just the way it is, I modify test.rb by
adding this method to class C:
def g x
puts x + 1
end
back to irb...
irb(main):005:0> c.g 1
NoMethodError: undefined method 'g' for #<c:0x2df909c>
from (irb):1
irb(main):006:0> load 'test.rb' #reloading the file, but _not_ creating a new c
=> true
irb(main):007:0> c.g 1
2
=> nil
Todd