# Extreme dynamism examples for showing off Ruby power

**URL:** <https://www.ruby-forum.com/t/extreme-dynamism-examples-for-showing-off-ruby-power/56167>\
**Category:** Ruby\
**Created:** [January 5, 2006, 4:04am UTC](https://www.ruby-forum.com/t/extreme-dynamism-examples-for-showing-off-ruby-power/56167 "2006-01-05T04:04:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [January 5, 2006, 4:04am UTC](https://www.ruby-forum.com/t/extreme-dynamism-examples-for-showing-off-ruby-power/56167/1 "2006-01-05T04:04:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [January 5, 2006, 5:07am UTC](https://www.ruby-forum.com/t/extreme-dynamism-examples-for-showing-off-ruby-power/56167/2 "2006-01-05T05:07:12Z")

</div>

Many solutions to the latest ruby quiz used breadth-first search, a  
classic computer science algorithm. There were a wide variety of  
solutions, filled with neat examples of ruby-isms. I’m sure you can  
find some gems for your presentation by looking here:

[http://www.rubyquiz.com/quiz60.html](http://www.rubyquiz.com/quiz60.html)

BTW - Here was my solution, which turned instances of Integers into  
an ad-hoc nodes.

[http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/173622](http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/173622)

~ ryan ~

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [January 5, 2006, 9:29am UTC](https://www.ruby-forum.com/t/extreme-dynamism-examples-for-showing-off-ruby-power/56167/3 "2006-01-05T09:29:23Z")

</div>

Dave S. wrote:

> 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
```

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [January 5, 2006, 9:53am UTC](https://www.ruby-forum.com/t/extreme-dynamism-examples-for-showing-off-ruby-power/56167/4 "2006-01-05T09:53:25Z")

</div>

On Thu, 05 Jan 2006 02:59:21 -0000, Dave S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> end

😃 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.
