Hacker News new | ask | show | jobs
by richcollins 5937 days ago
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) ...
2 comments

That is insanely ugly. I will pass, thanks.
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]

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

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