<p>Continuing the "Hidden features of ..." meme, let's share the lesser-known but useful features of Ruby programming language.</p>

<p>Try to limit this discussion with core Ruby, without any Ruby on Rails stuff.</p>

<p>See also:</p>

<ul>
<li><a href="https://stackoverflow.com/questions/9033/hidden-features-of-c">Hidden features of C#</a></li>
<li><a href="https://stackoverflow.com/questions/15496/hidden-features-of-java">Hidden features of Java</a></li>
<li><a href="https://stackoverflow.com/questions/61088/hidden-features-of-javascript">Hidden features of JavaScript</a></li>
<li><a href="https://stackoverflow.com/questions/709679/hidden-features-of-ruby-on-rails">Hidden features of Ruby on Rails</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python">Hidden features of Python</a></li>
</ul>

<p>(Please, just <em>one</em> hidden feature per answer.)</p>

<p>Thank you</p>

I find using the
define_method
command to dynamically generate methods to be quite interesting and not as well known.  For example:
```
```
((0..9).each do |n|
    define_method "press_#{n}" do
      @number = @number.to_i * 10 + n
    end
  end
```
```
The above code uses the 'define_method' command to dynamically create the methods "press1" through "press9."  Rather then typing all 10 methods which essentailly contain the same code, the define method command is used to generate these methods on the fly as needed.