# Favorite Ruby idioms, shortcuts?

**URL:** <https://www.ruby-forum.com/t/favorite-ruby-idioms-shortcuts/129273>\
**Category:** Ruby\
**Created:** [February 16, 2008, 12:37am UTC](https://www.ruby-forum.com/t/favorite-ruby-idioms-shortcuts/129273 "2008-02-16T00:37:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serg\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Serg\_K](https://www.ruby-forum.com/u/Serg_K)\
**Post date:** [February 16, 2008, 12:37am UTC](https://www.ruby-forum.com/t/favorite-ruby-idioms-shortcuts/129273/1 "2008-02-16T00:37:39Z")

</div>

Hi

As relatively new to Ruby, I’d be interested in seeing what people  
think are the best idioms for Ruby. I’m trying to get used to doing  
things the “Ruby way” (no pun intended). I’m interested in what you  
think are your favorite ways of doing things in Ruby. Please include  
a short description or comments. If I get enough of them I’ll  
consolidate them and post them online.

Thanks for all your help and time.

PS - Anyone have a good explanation of why RDoc translates initialize  
methods as ‘new’? Yes I know you instantiate via: X.new but why  
does the method ‘initialize’ get documented as method ‘new’? Seems  
a bit confusing for us newbies.

---

<div class="post-metadata">

**Author:** ![Serg\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Serg\_K](https://www.ruby-forum.com/u/Serg_K)\
**Post date:** [February 16, 2008, 1:11am UTC](https://www.ruby-forum.com/t/favorite-ruby-idioms-shortcuts/129273/2 "2008-02-16T01:11:08Z")

</div>

On Feb 15, 4:36 pm, Serg K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> As relatively new to Ruby, I’d be interested in seeing what people  
> think are the best idioms for Ruby. I’m trying to get used to doing  
> things the “Ruby way” (no pun intended). I’m interested in what you  
> think are your favorite ways of doing things in Ruby. Please include  
> a short description or comments. If I get enough of them I’ll  
> consolidate them and post them online.

[http://209.85.173.104/search?q=cache:6FhFfBVa9lIJ:rubygarden.org/Ruby/page/show/RubyIdioms+ruby+idioms&hl=en&ct=clnk&cd=2&gl=us&client=safari](http://209.85.173.104/search?q=cache:6FhFfBVa9lIJ:rubygarden.org/Ruby/page/show/RubyIdioms+ruby+idioms&hl=en&ct=clnk&cd=2&gl=us&client=safari)

> PS - Anyone have a good explanation of why RDoc translates initialize  
> methods as ‘new’? Yes I know you instantiate via: X.new but why  
> does the method ‘initialize’ get documented as method ‘new’? Seems  
> a bit confusing for us newbies.

I assume because initialize only exists to be called on instances  
after the ‘new’ for the class has created them. I have personally  
never called #initialize directly; it’s always through new.

I suppose the idea is that by documenting the method that you actually  
call, you know how to use the method. (Instead of causing new users to  
think that they should write f = Foo.new; f.initialize( bar, 42 )

---

<div class="post-metadata">

**Author:** ![Serg\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Serg\_K](https://www.ruby-forum.com/u/Serg_K)\
**Post date:** [February 16, 2008, 1:14am UTC](https://www.ruby-forum.com/t/favorite-ruby-idioms-shortcuts/129273/3 "2008-02-16T01:14:05Z")

</div>

> 

Thanks that makes sense.

---

<div class="post-metadata">

**Author:** ![Serg\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Serg\_K](https://www.ruby-forum.com/u/Serg_K)\
**Post date:** [February 16, 2008, 4:38am UTC](https://www.ruby-forum.com/t/favorite-ruby-idioms-shortcuts/129273/4 "2008-02-16T04:38:02Z")

</div>

Right. Your API documentation should typically document public API  
over private, internal implementation details. Though it does seem  
odd that somehow it doesn’t signify that the functionality documented  
as new is actually initialize. I don’t know if there’s really a good  
alternative to the current way it’s done, though.

–Jeremy

On Fri, Feb 15, 2008 at 7:13 PM, Serg K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > does the method ‘initialize’ get documented as method ‘new’? Seems

–  
[http://www.jeremymcanally.com/](http://www.jeremymcanally.com/)

My books:  
Ruby in Practice

> **[Ruby in Practice](https://www.manning.com/books/ruby-in-practice)**
>
> Like Ruby itself, Ruby in Practice will make you more productive. The book shows you practical techniques and strategies for small projects and large-scale environments. A cookbook-style reference, it gives you concrete examples of systems...

My free Ruby e-book

> **[Site not found · DreamHost](http://www.humblelittlerubybook.com/)**
>
> The owner of this domain has not yet uploaded their website.

My blogs:

> **[Site not found · DreamHost](http://www.mrneighborly.com/)**
>
> The owner of this domain has not yet uploaded their website.

[http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)
