Idiomatic Ruby

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Idiomatic Ruby

Leandro TK

Hello guys,


As all of you, I think Ruby a beautiful programming language. And I wrote a blog post about that.


I call it Idiomatic Ruby


Any comment or advice will alwasy be welcome :)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9deec1e6-c3d9-4882-ad92-9fda482f215e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Idiomatic Ruby

Scott Jacobsen
Nice post. But you shouldn't use any? to test if a collection is empty. To see why try it on this array: [nil, false] and read the docs. Use empty? to test if an array is empty. 

On Apr 1, 2017 12:02 AM, "Leandro TK" <[hidden email]> wrote:

Hello guys,


As all of you, I think Ruby a beautiful programming language. And I wrote a blog post about that.


I call it Idiomatic Ruby


Any comment or advice will alwasy be welcome :)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9deec1e6-c3d9-4882-ad92-9fda482f215e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAK5aKabA8GLfuVi7gbO3RfnU1N4YS3BG27tPojpqt8FBQkAHhg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Idiomatic Ruby

Leandro TK
Hey Scott,

You're absolutely right. If we want to ask an array if it is empty, we can use the .empty? method. But if we want to ask if the array has anything inside it, we can use .any? method :)



On Saturday, April 1, 2017 at 10:41:01 AM UTC-3, Scott Jacobsen wrote:
Nice post. But you shouldn't use any? to test if a collection is empty. To see why try it on this array: [nil, false] and read the docs. Use empty? to test if an array is empty. 

On Apr 1, 2017 12:02 AM, "Leandro TK" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="pVFzwTVjAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">leandr...@...> wrote:

Hello guys,


As all of you, I think Ruby a beautiful programming language. And I wrote a <a href="https://medium.com/the-renaissance-developer/idiomatic-ruby-1b5fa1445098" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2Fthe-renaissance-developer%2Fidiomatic-ruby-1b5fa1445098\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGhQLhBEDWSaVkAeO1jisDR0Lr1sA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2Fthe-renaissance-developer%2Fidiomatic-ruby-1b5fa1445098\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGhQLhBEDWSaVkAeO1jisDR0Lr1sA&#39;;return true;">blog post about that.


I call it <a href="https://medium.com/the-renaissance-developer/idiomatic-ruby-1b5fa1445098" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2Fthe-renaissance-developer%2Fidiomatic-ruby-1b5fa1445098\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGhQLhBEDWSaVkAeO1jisDR0Lr1sA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2Fthe-renaissance-developer%2Fidiomatic-ruby-1b5fa1445098\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGhQLhBEDWSaVkAeO1jisDR0Lr1sA&#39;;return true;">Idiomatic Ruby


Any comment or advice will alwasy be welcome :)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="pVFzwTVjAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonrails-ta...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="pVFzwTVjAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/9deec1e6-c3d9-4882-ad92-9fda482f215e%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/9deec1e6-c3d9-4882-ad92-9fda482f215e%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/9deec1e6-c3d9-4882-ad92-9fda482f215e%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/9deec1e6-c3d9-4882-ad92-9fda482f215e%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0d002cb8-6d71-46b2-968c-2feae0e4d331%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Idiomatic Ruby

Scott Jacobsen
That's not what #any? is for, but it is a common misconception. Try running the code I suggested you run, and read the docs I suggested you read to see why. To be more clear, try running this - `[false].any?` and `[false].empty?` and see if you get what you expect.

On Apr 1, 2017 8:44 AM, "Leandro TK" <[hidden email]> wrote:
Hey Scott,

You're absolutely right. If we want to ask an array if it is empty, we can use the .empty? method. But if we want to ask if the array has anything inside it, we can use .any? method :)



On Saturday, April 1, 2017 at 10:41:01 AM UTC-3, Scott Jacobsen wrote:
Nice post. But you shouldn't use any? to test if a collection is empty. To see why try it on this array: [nil, false] and read the docs. Use empty? to test if an array is empty. 

On Apr 1, 2017 12:02 AM, "Leandro TK" <[hidden email]> wrote:

Hello guys,


As all of you, I think Ruby a beautiful programming language. And I wrote a blog post about that.


I call it Idiomatic Ruby


Any comment or advice will alwasy be welcome :)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9deec1e6-c3d9-4882-ad92-9fda482f215e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0d002cb8-6d71-46b2-968c-2feae0e4d331%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAK5aKaZKhPt9m3NoYETBvqpO%3DL7-Mnf0GUndYLpMVSkxubb9SA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.