News for hackers. Stuff that matters.
Re:Ruby Best Practices (full book available for download) by richcollins on Thursday March 18, 2010 @02:21AM (#1200634)
With the hash args the order could vary so I had to keep looking up what the possible argument key values could be.

You can set slots on objects in any order that you want to:

    Foo.new.set_x(x).set_z(z) ...
Re:Ruby Best Practices (full book available for download) by jamesbritt on Thursday March 18, 2010 @04:13AM (#1200766)
That is insanely ugly. I will pass, thanks.
Re:Ruby Best Practices (full book available for download) by richcollins on Thursday March 18, 2010 @01:03PM (#1201798)
Setters are composable and you can modify their behavior. Hash literals ... not so much.

It would seem you only see the surface beauty of things. [redacted -- good point]

Re:Ruby Best Practices (full book available for download) by jamesbritt on Thursday March 18, 2010 @01:13PM (#1201835)
"It would seem you only see the surface beauty of things."

Is that how you defend an API? Insult the user?

Holy shit that's stupid.

Re:Ruby Best Practices (full book available for download) by extension on Monday April 19, 2010 @09:38AM (#1276652)
How about adding this to the Point class?

  def to_hash
    {:x => @x, :y => @y}
  end
  
  def to_ary
    [@x,@y]
  end

  def [] i
    case i
    when 0,:x
      @x
    when 1,:y
      @y
    end
  end
Should work if the receiving method interprets the arguments properly.
Re:Ruby Best Practices (full book available for download) by sandal on Thursday March 18, 2010 @10:19AM (#1201335)
Can you recommend an Io book for me? I want to hunt down the author and try to encourage them to make their code more Rubyish. Because you know, that's helpful.
Re:Ruby Best Practices (full book available for download) by richcollins on Thursday March 18, 2010 @01:02PM (#1201793)
I did recommend to the Io author that he create a Hash literal syntax because I like the fact that Ruby has one ;-)

To be clear, I think that it is great that you created this book. I just responded as I did because I'm often frustrated when I use Ruby APIs that sacrifice good design (imo) for syntactic terseness.