Extreme dynamism examples for showing off Ruby power

D

Dave Symonds

Hi All,

I'm giving a presentation to my research group next month about Ruby
(mainly an intro), but seeing as though it's in a Computer Science
department, with plenty of people who have several decades of
programming experience in many different languages, I'm trying to come
up with some examples of (among other things) how Ruby's dynamism can
be taken to extremes. My first thought was satisfying Orwell's famous
"Nineteen Eighty Four" proposition about mathematical adherence to Big
Brother:

class Fixnum
alias old_plus +

def +(arg)
if self == 2 and arg == 2
5 # INGSOC compliance
else
old_plus(arg)
end
end
end


Any improvements, or other neat little examples I can use? I've also
adapted the VCR-proxy example (pimple-class using method_missing to
catch, record and pass on method calls).



Cheers,

Dave.
 
R

Robert Klemme

Dave said:
Hi All,

I'm giving a presentation to my research group next month about Ruby
(mainly an intro), but seeing as though it's in a Computer Science
department, with plenty of people who have several decades of
programming experience in many different languages, I'm trying to come
up with some examples of (among other things) how Ruby's dynamism can
be taken to extremes. My first thought was satisfying Orwell's famous
"Nineteen Eighty Four" proposition about mathematical adherence to Big
Brother:

class Fixnum
alias old_plus +

def +(arg)
if self == 2 and arg == 2
5 # INGSOC compliance
else
old_plus(arg)
end
end
end


Any improvements, or other neat little examples I can use? I've also
adapted the VCR-proxy example (pimple-class using method_missing to
catch, record and pass on method calls).

I always like the interchangeability of lambda#[] and Hash#[] which allows
for poor man's memoize:

fun = lambda {|x| x + 10 - 2}
code = optimize ? Hash.new {|h,k| h[k] = fun[k]} : fun
1000.times { code[100] }

Admittedly a silly example... :)

robert
 
R

Ross Bamford

Hi All,

I'm giving a presentation to my research group next month about Ruby
(mainly an intro), but seeing as though it's in a Computer Science
department, with plenty of people who have several decades of
programming experience in many different languages, I'm trying to come
up with some examples of (among other things) how Ruby's dynamism can
be taken to extremes. My first thought was satisfying Orwell's famous
"Nineteen Eighty Four" proposition about mathematical adherence to Big
Brother:

class Fixnum
alias old_plus +

def +(arg)
if self == 2 and arg == 2
5 # INGSOC compliance
else
old_plus(arg)
end
end
end

:D Like it.
Any improvements, or other neat little examples I can use? I've also
adapted the VCR-proxy example (pimple-class using method_missing to
catch, record and pass on method calls).

Well, I don't know how much they'll impress such old salts, but you can
find examples of my wide-eyed wonderment in my Nuby files:

http://roscopeco.co.uk/code/noob/

Maybe it can provide a few ideas for things to look at.
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top